Amazon EC2 Instance - Where to add the credentials file? - amazon-web-services

I have an Amazon EC2 Instance. On my Instance I want to run a python program. The program tries to access other amazon services. On my Mac the program worked fine, because the credentials file is in the folder "~/.aws/credentials". But I don't know where on my amazon EC2 instance the library "~" is. So where do I have to put my credentials? Hope you can help me.

~ is a shortcut for your home directory. Just go into that directory using the command cd ~. This is the directory you will always start in when you SSH into your server.
Alternatively you could install the AWS CLI and run aws configure. If you are using Amazon Linux then the AWS CLI tool is already installed.
Also, storing credentials on your EC2 instance is not the preferred method. You should look into using EC2 instance profiles.

Related

How can I view files in EC2 instance?

I have just started learning about AWS. I am following along a tutorial and I have created a hello.txt file in EC2 using PuTTY on Windows. I wanted to know where I can see all the files listed in the EC2 instance on a GUI. I believe they are not stored locally on my computer; but I cannot find them on the AWS console either? Thank you.
PuTTY console screenshot
After some more AWS training, I found out that I can also see the files and folders in my EC2 instance in a "GUI" format using the Fleet Manager in AWS Systems Manager. The Systems Manager Agent must be installed in the EC2 instance and the instance must be given the appropriate permissions using IAM.
I wanted to know where I can see all the files listed in the EC2 instance on a GUI
Short answer:
Using a Windows PC to access an AWS EC2 you use PuTTY to navigate the file system. The hello.txt file you created is listed.
To open it you can do a cat hello.txt.
Official Answer:
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-2-install-gui/
The instructions get you to install the MATE desktop environment, a lightweight GUI based on GNOME 2 available as an extra for Amazon Linux 2.

Invoking Windows EC2 terminal remotely

I need to connect to my Windows EC2 terminal to invoke a local script on it from a different machine CMD.
I tried to search and I 'v found the following: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Connect-using-EC2-Instance-Connect.html. This solves the problem for Linux, not windows. Any suggestion or lead for a solution?
On Windows machines, you can remotely SSH onto your EC2 instance using a bash shell, which supports SSH.
If you have git bash installed, it can do the trick for you.
You will need the pem file which you can generate before launching your EC2 instance, at the very last step. Else, you can also use your own key - see docs from AWS here.
You can look into the option of session manager.
Please refer: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html
To give you a brief, Session Manager is a fully managed AWS Systems Manager capability that lets you manage your Amazon EC2 instances, on-premises instances, and virtual machines (VMs) through an interactive one-click browser-based shell or through the AWS CLI.

Do I have to install AWS CLI in each server?

I have multiple standalone servers from where I want to upload/sync directories to Object Storage usign AWS CLI.
Do I have to install AWS CLI in each server? OR is there a common console/platform provided within AWS Object Storage from where I can call the same command over something like say SSH. How can I avoid installing cli to all the servers?
You have to install AWS CLI in all the servers even if you write the script to ssh from a single server that which is installed AWS CLI, SSH protocol will take the configuration from the remote server, not from a server where the script is running. It's better if you use a configuration management tool like ansible to speed up the process.

Run exe file on EC2 from AWS Lambda

I have a requirement to run a .exe file with the SQS event message as parameter. The .exe is installed on EC2. Is it possible to invoke the exe from the AWS Lamda function?
The best way to run scripts on EC2 instances from outside of the EC2 instance is probably to use AWS Systems Manager Run Command.
The setup is fairly simple:
your EC2 instance needs to include the SSM Agent (it probably already does if it was launched from an Amazon-provided Amazon Linux or Ubuntu AMI)
your EC2 instance needs to be launched with an IAM role with an attached AmazonEC2RoleforSSM policy, see here
your Lambda function needs an IAM role allowing it to invoke Run Command (the action is ssm:SendCommand)
Alternatively, you could do this in other ways, for example:
use Fabric or Paramiko to exec commands over SSH
install a web server on the EC2 instance that allows you to remotely invoke an API to execute the script

Where can I find private key file for EC2 instance I create through Elastic Beanstalk CLI?

I'm 100% new to AWS and I'm working on deploying my personal site. I've spun up an EB environment via the AWS EB CLI and but I would also like to be able to SSH into the EC2 instance that gets created however I can't locate the private key (.pem) file that is associated with it which I need to chmod for permit SSH'ing in.
Does a private key file get created when you create an EC2 instance via Elastic Beanstalk? If so where can I find it? Thanks a ton.
It is so valuable question for the AWS beginners.
I was also confused with this question but get clear after a while.
I know you used the EB CLI for handling the EB.
With the EB CLI you don't need the .pem file for normal use.
Because the EB CLI has 'eb ssh' for connecting the EC2 instance of your EB.
Please check out : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-ssh.html
Also you can't get the standard .pem file of your EB.
There are some steps.
Please check out : SSH to Elastic Beanstalk instance
Elastic beanstalk still provisions EC2 instances and an SSH key can be assign to them.
You have two options if you didn't attach a key to an instance at provision time or have since lost it.
Provision a new instances with a key attached to it.
Snapshot the instance, Provision a new instances with a key attached and references the snapshot id of the old instance.
One should be easier with Elastic Beanstalk, just provision a new environment with keys attached to the instance, you will lose data with this method though.
More in depth steps for #2 can be found here
. This will help you retain data if need be.
eb ssh only works if you have the keys and have attached them to the instance. Private key files must be located in a folder named .ssh under your user directory
eb init will ask if you want to ssh into your instance, then list out the keys in your account in that region. If a new key was created it should have outputted where the key was place on your filesystem.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-init.html
eb create has a -k key option as well
If you include this option with the eb create command, the value you provide overwrites any key name that you might have specified with eb init.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-create.html