To deploy to AWS you need to set up some AWS credentials following these steps:
- Create a new user in AWS IAM
- With “programmatic access” only
- “Attach existing policies directly” – choose “AdministratorAccess”
- Create the user but DON’T CLOSE THE CREDENTIALS SCREEN
- Add the credentials to your computer (AWS CLI or manually edit the file)
That’s all you need to do. Now you can make requests to your AWS account using the Serverless Framework, CDK or CLI.
If you want some more detailed steps then here they are:
Create a new user in AWS IAM
To create a user, log into your AWS console and search for IAM. Click on users
on the left menu and then Add users
.
Give your user profile a name and set it to have Access key - Programatic access
only.
Click Next: Permissions
and here we’re going to Attach existing policies directly
choosing the AdministratorAccess
policy.
Click Next
until you get to the Create user
screen that looks like this. Stop here and do not click close
.
Add AWS credentials to your computer
There are two ways add your AWS Credentials via the CLI or by manually editing the file.
Adding with CLI
First you need to make sure you have the AWS CLI installed.
%: aws --version
aws-cli/2.4.13 Python/3.8.8 Darwin/21.5.0 exe/x86_64 prompt/off
If you don’t get a message like that, you need to install the AWS CLI first.
Now you can run AWS Configure. You then just copy and paste in your access key, secret access key, default region and output format.
aws configure
Optionally you can add --profile profileName
to your command to give these credentials a name. This is useful if you work with multiple AWS accounts
aws configure --profile yourProfileName
Manually editing the credentials file
Another way is to open the credentials file. This file is usually found at ~/.aws/credentials
. You may need to show hidden files in your file browser. For Mac press Command + Shift + .
Your file may be empty or may not even exist. If it doesn’t exist create an empty file. In that file you can now paste your credentials in this format. You can either set those credentials to be your default or give them a profile name.
[default]
aws_access_key_id=${Your access key ID}
aws_secret_access_key=${Your secret access key}
[serverlessUser]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
What Next?
The next thing to do is to start building out your API. My Ultimate Guide to Serverless is a great place to start.