Setting up AWS CLI credentials

Lloyd Hamilton
3 min readJan 12, 2022

--

A guide to integrating AWS with Serverless Application Module

Photo by Hello I'm Nik on Unsplash

First we will have to create a new user on AWS and assign the right permissions before deploying from our machine to AWS in command line.

Let’s take it step by step.

a) Log into AWS console.

Image by author

b) In your console, select All Services then Security, Identity & Compliance then IAM.

c) On the left hand tab, select Users. If you do not see the left hand tab, click on the three back bars directly below the AWS logo on the top left hand corner.

d) Select Add User and give the user a username. Ensure the Access key — Programmatic access checkbox is selected then click Next

Image by author

e) AWS Serverless Application Model (SAM) will require access to several AWS resources, therefore several policies will need to be applied. Think of these policies as keys that will unlock the resources that SAM will be interacting with. Without these policies, SAM will not have the necessary permissions to build the serverless framework to deploy your application.

To attach a policy, search for the policy in the search box and select the check box.

Attach the following policies for this user:

  • IAMFullAccess
  • AmazonEC2ContainerRegistryFullAccess
  • AmazonS3FullAccess
  • AmazonAPIGatewayAdministrator
  • AWSCloudFormationFullAccess
  • AWSLambda_FullAccess
Image by author

f) Skip the Add tags section and create user in the review section

g) On successful creation, copy the Access Key ID and Secret Access Key onto a notepad or download the .csv for safe keeping. We will need these keys to finish setting up AWS CLI.

h) To configure AWS CLI, open a new terminal window and use the command:

aws configure

Follow the prompts and add your Access Key ID and Secret Access Key where appropriate. You may choose a default region from this list or choose to leave it as None. In my case, it is pre-configured to use eu-west-2 as my default region and json as the default output format.

Image by author

i) Test the connection.

aws sts get-caller-identity

The response should return a JSON object with the details of the user making the call.

Image by author

For more details, check out the official documentation detailing all the tool you now have access to through command line.

--

--

Lloyd Hamilton

Data Scientist at IGS | Data Instructor | Certified AWS Cloud Practitioner | Passionate about all things data.