Using AWS Programmatically is a good to have skill. In this first tutorial, we begin by setting up authentication on our terminal.
We will work with YAML files for automation for future use cases but wonʼt be covered here.
Terminal Set-up CLI
Open terminal, I will be using visual studio terminal on Mac.
Create folder for your project.
mkdir aws_project
cd aws_project
create gitignore file -> .gitignore
Open terminal and run the following command for mac.
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
To get the instructions for other OS check out. https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
Create IAM user
Navigate to your aws console and search for IAM. We will be creating an admin user to authenticate to aws from terminal.
Click on users in the left panel and create user
Use a descriptive name for the username and click next.
It is the best option to add user to a group instead of attaching policy directly. Create a group with a descriptive name as well.
Attach the AdministratorAccess policy to the group since we will use this user to create multiple resources. For future users, adopt the principle of least priviledge and provide fine-grained access to actions and resources
Then create the user
Click on created user and navigate to Security credentials. We will create an access key to make programmatic calls from terminal. Click on next.
Now we have created a user with required policy attached and have the secret values needed to identify from terminal. This credentials are long lived but can be rotated manually incase needed.
Configure Credentials in Terminal
Next we set the environment variables, replacing the examples shown with values retrieved from console.
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-west-2
To confirm that you are successfully authenticated run the command
aws sts get-caller-identity
To confirm if successful, list buckets present in account
aws s3 ls
Top comments (0)