Pip Potter 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
..
core 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
example 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
.gitignore 75dc720198 Integrating latest 47acbe8 3 anni fa
README.md 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
app.py 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
architecture.png 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
cdk.json 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa
constants.py 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213) 3 anni fa
requirements.txt 81d22bc742 Migrate AWS Gems to CDKv2 (#11675) 1 anno fa

README.md

Welcome to the AWS Core CDK Python project!

This is the long term supported CDK v2 version of this template. If you have preexisting versions of this template see the CDK migration guidance about upgrading to CDK v2.

This is an optional CDKv2 application that provides two stacks:

  • A core stack to use as the basis for a project's CDK application
  • An example stack with example resources that can be connected to ScriptBehavior samples in Core

The cdk.json file tells the CDK Toolkit how to execute your app.

This project is set up like a standard Python project. The initialization process also creates a virtualenv within this project, stored under the .env directory.
To create the virtualenv it assumes that there is a python3 (or python for Windows) (Python 3.7+) executable in your path with access to the venv package. If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv manually.

The CDK Getting Started Guide covers information about how to set up the prerequisites for CDK development.

For information about working with the CDK and O3DE, see the Deploying the CDK Application section on o3de.org.

Note: This stack is for CDK v2 (the latest CDK version), if you are working with CDKv1 stacks please use the CDKv1 version of this application.

Make a virtual environment

To manually create a virtualenv on macOS and Linux:

$ python -m venv .venv

Once the virtualenv is created, you can use the following step to activate your virtualenv.

$ source .venv/bin/activate

If you are a Windows platform, you would activate the virtualenv like this:

% .venv\Scripts\activate.bat

Once the virtualenv is activated, you can install the required dependencies.

$ pip install -r requirements.txt

Set environment variables or accept defaults

  • O3DE_AWS_DEPLOY_REGION: The region to deploy the stacks into, will default to CDK_DEFAULT_REGION
  • O3DE_AWS_DEPLOY_ACCOUNT: The account to deploy stacks into, will default to CDK_DEFAULT_ACCOUNT
  • O3DE_AWS_PROJECT_NAME: The name of the O3DE project stacks should be deployed for will default to AWS-PROJECT

See CDK Environments for more information including how to pass parameters to use for environment variables.

Synthesize the project

At this point you can now synthesize the CloudFormation template for this code.

$ cdk synth

You may need to perform a one time CDK bootstrap, once per account, per region. The CDK application will prompt you on this.

To add additional dependencies, for example other CDK libraries, just add them to your requirements.txt or setup.py file and rerun the pip install -r requirements.txt command.

Optional Features

Optional features are activated by passing runtime context variables. To use multiple optional features together provide one key-value pair at a time:

cdk synth --context key1=value1 --context key2=value2 MyStack

Automatic S3 and DynamoDB Cleanup

The S3 bucket and Dynamodb created by the sample will be left behind as the CDK defaults to retaining such storage (both have default policies to retain resources on destroy). To delete the storage resources created when using CDK destroy, use the following commands to synthesize and destroy the CDK application.

cdk synth -c remove_all_storage_on_destroy=true --all
cdk deploy -c remove_all_storage_on_destroy=true --all
cdk destroy --all

Server Access Logging

Server access logging is enabled by default. To disable the feature, use the following commands to synthesize and deploy this CDK application.

$ cdk synth -c disable_access_log=true --all
$ cdk deploy -c disable_access_log=true --all

See https://docs.aws.amazon.com/AmazonS3/latest/userguide/ServerLogs.html for more information about server access logging.

Deploy

This CDK application has two stack, so use

cdk list
cdk deploy <stackname>

Useful commands

  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

Troubleshooting

See Troubleshooting common AWS CDK issues for help.