CLI, CloudShell, CDK, SAM

circle-info

Update the awscli regularly

[2022-Jun] aws-cli/2.7.9 Python/3.9.11 Windows/10 exe/AMD64 prompt/off

Explore further

AWS CLI

The AWS Command Line Interface (AWS CLI) enables you to interact with AWS services using commands in your command-line shell.

Setup

Install unzip

$ sudo apt install unzip

Install - AWS CLI

Source: AWS Installing or updating the latest version of the AWS CLIarrow-up-right

circle-info

Update the awscli

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip

$ sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

aws-cli/2.17.14 Python/3.11.9 Linux/5.15.153.1-microsoft-standard-WSL2 exe/x86_64.ubuntu.22

Configure - AWS CLI

Source: AWS CLI - Quick Setup - New configuration quick setuparrow-up-right

  • For new & clean environment, configure the "default" config and profile

The configurations are stored in the ~/.aws folder for (macOS/Linux); or %USERPROFILE%.aws\ folder for (Windows), in two files: config and credentials

  • [Optional] Configure for a specific "profile", for example: "produser"

Docs - AWS CLI

How-to

chevron-rightGet: account number, default regionhashtag
chevron-rightafter windows update aws error: bus errorhashtag

Resolution: reinstall aws cli; see Setup

chevron-rightSetup environment variableshashtag
chevron-rightGet AWS Account Number using aws stshashtag

aws sts - Secure Token Service

CloudShell

Source: AWS CloudShellarrow-up-right

Command line access to AWS resources and tools directly from a browser.

There is no additional charge for AWS CloudShell.

Useful commands to explore:

  • zsh; vim ~/.zshrc

CDK

The AWS Cloud Development Kit (AWS CDK) is a software development framework for defining your cloud application resources using familiar programming languages including: Python, Typescript, etc. Regardless of the programming languages, CDK uses the same back end which runs on Node.js. Therefore, the development computer needs to have the Node.js prerequisite installed.

Source: Getting started with the AWS CDKarrow-up-right

Step-by-Step Instructions

CDK credentials requirements

Ensure the development computer has been configured with the "region" and "credentials" in the config and credentials files, respectively. Both files are stored in the ~/.aws folder. For more details, see Configure - AWS CLI.

NOTE: although the AWS CDK uses credentials from the same configuration files as the AWS CLI, it behaves differently. If you use a named profile from the credentials file, the config file must have a profile of the same name specifying the region. In addition, do not use a profile named containing the word "default" (e.g. [profile default]). [see Getting started with the AWS CDKarrow-up-right]

Install - CDK

CDK Bootstrapping

Deploying stacks with the AWS CDK requires the AWS CloudFormation stack (called CDKToolkit) and a dedicated Amazon S3 buckets to be available during deployment. The process is called bootstrappingarrow-up-right, and it's a onetime setup for the AWS Account. The S3 bucket and the CloudFormation "CDKToolkit" resources are reusable by any cdk projects.

During "CDK bootstrapping", the following five IAM Roles are also created:

CLEANUP

As mentioned above, the resources created by bootstrapping are reusable across cdk projects so they should not be deleted. However, to completely cleanup all the resources created during CDK bootstrapping:

  • Delete the S3 bucket

  • Delete the CloudFormation "CDKToolkit"

  • Delete the five IAM roles; go to IAM console, and search for "cdk-"

[Optional] Setup User Policy

  • Define user policy needed to deploy AWS S3.

circle-info

If the user belongs to the Administrator group; then the following policy will not be needed.

Tutorials

Docs - CDK

Troubleshooting

chevron-rightcdk deploy error: fail: No bucket named; Is account <acct#> bootstrapped?hashtag

One of the two resources created by the cdk bootstrap: the S3 bucket or the CloudFormation stack called "CDKToolkit" was not delete. Note: if you only delete the S3 bucket, the next cdk deploy will fail indicating that the account has not been "bootstrap" but attempt to cdk bootstrap will look like success with "no change" shown on the output, but the S3 bucket is not created and the cdk deploy will still fail, as shown below. The reason is because cdk bootstrap still detects the CloudFormation resource, i.e., "CDKToolkit".

chevron-rightcdk deploy error: current credentials could not be used to assumehashtag

AWS CLI SAM

Source: AWS Serverless Application Model - Installing the AWS SAM CLIarrow-up-right

Prerequisite: AWS CLI version 2arrow-up-right

  • Verify the integrity and authenticity of the downloaded installer files by generating a hash value using the following command:

  • Unzip the installation files into the sam-installation/ subdirectory

  • Install the AWS SAM CLI

References

Last updated