Sign inSign up

gclim/aws-cdk-python

By gclim

Updated over 5 years ago

AWS Cloud Development Kit with Python

Image
1

1.1K

gclim/aws-cdk-python repository overview

Docker aws-cdk-python

AWS Cloud Development Kit with Python & AWS CLI

1. Getting Started

These instructions will cover usage information and for the docker container

Prerequisities

In order to run this container you'll need docker installed.

2. Starting A New Project

2.1 Usage with Docker run
2.1.1 Run aws-cdk

Run the following in a newly created or existing project directory.
Refer to Run aws-cdk with AWS environment variables below for passing environment variables.
Bash will keep the container running.

docker run --name aws-cdk -it -d -v $(pwd):/user-app gclim/aws-cdk-python bash
2.1.2 Run aws-cdk to init app with Python

Note: For initiating a new CDK project only.

docker exec -t aws-cdk cdk init app --language=python
2.2 Usage with Docker interactive session
2.2.1 Start interactive session with aws-cdk

Initiating terminal session with the aws-cdk docker container.

docker exec -ti aws-cdk bash
2.2.2 Initializing app using cdk

Note: For initiating a new CDK project only within the docker container.

cdk init --language python
2.2.3 Using CDK commands
cdk [diff|deploy|list|help]

Refer to CDK guide to get started
https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html

2.2.4 Configure AWS

For configuring AWS credentials either on the docker host or within aws-cdk docker container.
Note: Not required if using AWS environment variables.

aws configure

3. Resuming An Existing Project and Passing AWS Environment Variables

3.1 Usage with Docker run
3.1.1 Run aws-cdk with AWS environment variables

Run the following in a newly created or existing project directory.
Bash will keep the container running.

docker run \
  --name aws-cdk -it -d -v $(pwd):/user-app \
  -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
  -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  gclim/aws-cdk-python bash

Then use docker exec -ti aws-cdk bash for interactive session.

3.2 Usage with Docker for non-interactive process
3.2.1 Run aws-cdk with AWS environment variables with CDK commands

Run the following in a newly created or existing project directory.
The container will terminate after completion of the process.
Refer to CDK document for list of commands, or use help.

docker run \
  --rm -v $(pwd):/user-app \
  -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
  -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  gclim/aws-cdk-python [diff|deploy|list|help]

4. Deployment

4.1 Provision AWS using CDK codes from GitHub
4.1.1 Run aws-cdk with AWS environment variables

Run the following to start Docker container.
Bash will keep the container running.

docker run \
  --name aws-cdk -it -d \
  -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
  -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  gclim/aws-cdk-python bash
4.1.2 Clone a Project from GitHub

Run the following to clone the project from GItHub.

docker exec -it aws-cdk git clone https://github.com/username/project_name.git .
4.1.3 Update Dependencies using PIP

Run the following to update the dependencies.

docker exec -it aws-cdk pip install -r requirements.txt
4.1.4 CDK Deploy

Run the following to provision AWS using CDK.

docker exec -it aws-cdk cdk deploy
4.2 Provision AWS using CDK codes from GitHub using Docker run

Single command line to clone, pip install requirements and deploy.
The container will terminate after completion of the process.

docker run --rm -it \
  -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
  -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
  -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
  -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
  gclim/aws-cdk-python /bin/bash -c "git clone https://github.com/username/project_name.git .; pip install -r requirements.txt; cdk deploy"

5. Finishing A Project

5.1 Stopping Docker aws-cdk

By default, Docker waits 10 seconds before killing it.
Use -t option to set wait time.

docker stop aws-cdk

6. User application environment

  • /user-app - user app directory for CDK project
  • /root/.aws - aws profiles and credentials

7. Built With

  • Linux 189fc2213ae6 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 Linux
  • Python 3.7.4
  • node v10.19.0
  • npm 6.13.4
  • git version 2.22.4
  • aws-cli/1.19.11 Python/3.7.4 Linux/4.15.0-112-generic botocore/1.20.11
  • cdk 1.90.0 (build 7edba31)

Tag summary

Content type

Image

Digest

Size

115.9 MB

Last updated

over 5 years ago

docker pull gclim/aws-cdk-python