Creating and deleting an AWS EC2 instance from shell - linux

I was wondering if I could use a shell script on a remote server to create an amazon EC2 instance from an existing saved snapshot, and also delete that instance too.
I was sure it was possible, but I havent been able to run any example code to do it so im starting to doubt it now.
So, can anyone tell me how this is done please?

There is a quite detailed description on the Amazon webpage how to do this:
http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/Welcome.html
At which point are you struggling?

Related

Write and read files from AWS EC2 instance to Microsoft One Drive/SharePoint

I have an EC2 instance running from which I'd like to write a file to Microsoft One Drive. From the same EC2 instance I'd also like to read a file from One Drive/SharePoint. I'd like both the reads and writes to happen from the instance, not my local machine.
Is there a way to write files to One Drive from EC2, either through scp or through an API for One Drive? If so, how can I do this?
Please let me know if I can clarify my question further.
Thanks a lot

Running a script in an EC2 Linux Instance from AWS Lambda

Ive been looking for ways to create a lambda function that can access directly the contents of an EC2 Linux instance. My goal is to be able to call a script residing in the home directory AND pass in a variable which the script will use for processing.
Ive been looking at different ways of doing it, but I cant seem to find a concise solution.
Thank you in advance!
If your instance has the SSM agent running on it then your Lambda can run the send-command.
Using the AWS-RunShellScript document your Lambda can execute a number of commands on your EC2 instance for you.
You could also create your own document for SSM passing in an argument for each of the variables.

Change db instances in ForestAdmin and Lumber

As admin part I want to use ForestAdmin.
Also I am gonna use already existing database (Mattermost`s actually).
Everything was deployed to AWS (ForestAdmin and Mattermost).
Due to tutorial I can install ForestAdmin via Lumber and connect it to existing db. Actually I have done this, do some playing with code to expand some functionalities.
The main question is: when I install ForestAdmin locally via Lumber - I point to my local instance of database and lumber generates code (models and CRUD). So also I can install ForestAdmin locally and point to Mattermost`s database on AWS. BUT can I somehow change which database I want to use - local or that one on AWS?
Maybe I explain this problem bad - so also I will try to rephrase with example of desired flow:
Mattermost with database already installed on AWS
ForestAdmin also installed via Lumber and connected to Mattermost`s db
I got local instance of Forestadmin and Mattermost, write some code, test it in local environment.
Push to repo, connect via ssh to AWS and pull changes which was made.
AWS instances works as local but with separate instances of db.
Or maybe there is some better way to push changes from local Forestadmin and pull it to AWS instance of Forestadmin?
Thanks for any help in advance!
Yes you definitely can, you can use Forest environment for that :
https://docs.forestadmin.com/documentation/reference-guide/how-it-works/environments

AWS Linux API Patching

I am having around 300 red hat server on AWS which are hosting application. I want to make sure that my Linux instances are up to date from security and other point of view. Also i can not launch a new linux instance and delete the old one to get update one.
Can anyone please suggest me how to patch the AWS linux instances from a centralize location to all 300 servers.
Thanks
Manu.
This seems like a DevOps type question there are many ways to script this use the AWS API and the like in many languages from Python (Using something like Paramiko) or even straight up bash.
Provided you have the keys to access these linux instances the script should be trivial:
Get List of 300 servers from AWS using boto3 or awscli
Iterate over the server set to find the IP which you can SSH (private/public)
SSH to the instance and assume the root account
perform the yum update | yum upgrade command
Log out and move on to the next
Get a coffee and wait
Hope that helps!
Thanks,
//P

Is a Amazon Machine Images (AMI's) static or it's code be modified and rebuilt

I have a customer who wishes me to do some customisations of the erp system opentaps, which they used via opentaps Amazon Elastic Computing Cloud (EC2) images, I've only worked with it on a normal server and don't know anything about images in the cloud. When I ssh in with the details the client gave me there is no sign of the erp installation directory I'd expect to see. I did originally expect that the image wouldn't be accessible, but the client assured me it was. I suppose they could be confused.
Would one have to create a new image and swap it out or is there a way to alter the source and rebuild like on a normal server?
Something is not quite clear to me here. First of all EC2 images running in the cloud are just like normal virtual servers, so If you have an access to the running instance there is no difference between instance in the cloud and instance on another pc in your home for example.
You have to find out how opentaps are installed on the provided amis, then do your modifications, create an image from the modified instance and save it to s3 for backup if necessary.
If you want to start with fresh instance, you can start up any linux/windows distro on the EC2, install opentaps yourself your way and you are done.

Resources