This repo provides an all in one deployment of aws's modern application workshop Mythical Mysfits.
Specifically this repo will deploy all modules (1-7) of the python-cdk branch with minor alterations. The 7th module will need manual editing in order to become functional. Please follow the module-7 instructions to set REPLACE_ME_SAGEMAKER_ENDPOINT in the lambda-recommendations service
We will assume that you have an aws profile setup. Specific profiles can be specified by passing --profile=profile_name
to any cdk command.
- Install aws-cdk.
npm install -g aws-cdk
- Install dependancies.
cd cdk && npm i
- Bootstrap cdk if you have never done so.
cdk bootstrap
- Create an ecs service role if you have never done so.
aws iam create-service-linked-role --aws-service-name ecs.amazonaws.com
- Ensure docker is installed locally.
- Ensure your
AWS_PROFILE
environmental variable is set if you want to run scripts.
To deploy all modules 1-6 (and infrastructure for 7), load test data, and enable user self-registration run the following. Ensure AWS_PROFILE
is set.
$ export AWS_PROFILE="<your profile name>"
$ export CONTACT_EMAIL="<your email address>" # Optional, defaults to [email protected] (See cdk/lib/xray-stack.ts:65)
$ scripts/up.sh
The stack can be deleted by running
$ scripts/teardown.sh
Stack creation takes approximately 35 minutes.
The infrastructure definition is entirely handled by cdk, however containers still need to be manually built and pushed to ecr.
This stack can be simply deployed as follows.
$ cd cdk
$ cdk deploy '*'
This will generate interactive prompts asking you to confirm the creation of some resources. To avoid this you can specify the --require-approval never
flag.
$ cdk deploy --require-approval never '*'
The code container needs to be manually built and pushed after the ecr resource has been deployed. This typically only takes 2-3 minutes after initiation of deployment.
The following steps can be automatically executed with scripts/build_container.sh
.
Before building we setup some variables for convinience
$ cd assets/app
$ mm_aws_accountid=$(aws sts get-caller-identity --query Account --output text)
$ mm_aws_region=$(aws configure get region)
$ mm_container_name="mythicalmysfits/service"
The container can be built and tagged with
$ cd assets/app
$ docker build -t $mm_container_name .
$ docker tag $mm_container_name:latest $mm_aws_accountid.dkr.ecr.$mm_aws_region.amazonaws.com/$mm_container_name:latest
Next we can sign-in to the ecr registry and push our image
$ aws ecr get-login-password --region $mm_aws_region | docker login --username AWS --password-stdin $mm_aws_accountid.dkr.ecr.$mm_aws_region.amazonaws.com
$ aws ecr push $mm_aws_accountid.dkr.ec.$mm_aws_region.amazonaws.com/$mm_container_name:latest
Now the infrastrcture exists we will need to fix up some REPLACE_MEs in the environment. This can be done by running
$ scripts/postinstall.sh
To load test data and allow unmoderated signup run the following
$ scripts/load_test_env.sh
Stack deletion takes approximately 25 minutes.
Running cdk destroy
is adequate to teardown a majority of the infrastructure. There are however a few resources that will need to be manually deleted.
Note: cli assumes aws-cli v2
Parent Stack | Resource | Console | CLI |
---|---|---|---|
KinesisFirehose | kinesisfirehose-bucket | S3 > Select bucketname > Delete | aws s3 rb s3://mythicalmysfits-kinesisfirehose-bucket<uniq>-<uniq> |
CICD | cicd-pipelineartifactsbucket | S3 > Select bucketname > Delete | aws s3 rb s3://mythicalmysfits-cicd-pipelineartifactsbucket<uniq>-<uniq> |
ECS | ECS-ServiceTaskDefMythicalMysfitsServiceLogGroup | CloudWatch > Log groups > Select loggroupname > Delete | aws logs delete-log-group --log-group-name MythicalMysfits-ECS-ServiceTaskDefMythicalMysfitsServiceLogGroup<uniq>-<uniq> |
XRay | MysfitsQuestionsTable | DynamoDB > Select tablename > Delete Table | aws dynamodb delete-table --table-name MysfitsQuestionsTable |
Website | website-bucket | S3 > Select bucketname > Delete | aws s3 rb s3://mythicalmysfits-website-bucket<uniq>-<uniq> |
ECR | mythicalmysfits/service | ECR > Select repositoryname > Delete | aws ecr delete-repository --repository-name mythicalmysfits/service --force |
DynamoDB | MysfitsTable | DynamoDB > Select tablename > Delete Table | aws dynamodb delete-table --table-name MysfitsTable |
There are a few changes compared to the upstream vesion.
- The dockerfile (
/assets/app/Dockerfile
) has been changed to installpython3-*
. References topip
have been changed topip3
and the entrypoint modified topython3
. - Some instructional commands have been adapted to AWS-CLI v2 (namely those involved in signing to ecr).
- A helper function has been introduced to the cdk stacks in order to normalize references to assets.
- Changed some depreceated code to more mdoern versions (i.e.
lambda.Code.asset
->lambda.Code.fromAsset
)