Author: Jörn Meyer
Last change: 2023-02-02
In order to use AWS CDK to build AWS stacks, you need to install the aws
and cdk
command line tools first:
- Follow the AWS CLI install instructions for your operating system.
- Run
npm install -g aws-cdk
In your home folder, there should be a folder called .aws
(ls ~/.aws
if you're unsure). Create it if it doesn't exist. Find or create two files:
config
stores the profile names and configuration pertaining to themcredentials
stores your API credentials
Make a new section in config
:
[your-profile-name]
region=eu-central-1
- Log into the AWS console.
- Click on your username in top right corner.
- Choose Security credentials from the dropdown.
- Find the section called Access keys and click the button labelled Create access key
- Select Command line interface from the radio button menu. Check the checkbox labelled I understand the above recommendation and want to proceed to create an access key.
- Provide your new credentials with a fitting name, like
cli-access
and click Create access key - The next menu shows you the Access key and the Secret access key. Write them both down in your password manager of choice, as you can never access them again after you close the menu.
Edit ˜/.aws/credentials
and add:
[your-profile-name]
aws_access_key_id=ACCESS_KEY_YOU_JUST_CREATED
aws_secret_access_key=SAME_BUT_FOR_SECRET
After these steps are complete, you can execute the command export AWS_PROFILE=your-profile-name
to select your profile. You will have to do this every time you open a new terminal / shell. If you want to avoid that, you can also give your profile the name default
, but I would discourage that, since the export
route makes you consciously choose the correct profile before you perform any potentially destructive actions.
That's it! Both aws
and cdk
are now working with your selected profile.