Project infrastructure written in CDK Typescript.
The project consists of several CloudFormation stacks:
1 * CommonStack- deploys resources shared across all applications (VPC, ALB, ECS Cluster, Route53 Hosted Zone)1 * DatabaseStack- deploys Aurora PostgreSQL cluster shared across all applicationsN * ApiServiceStack- deploys project APIs hosted on ECSN * FrontendStack- deploys project frontends hosted on S3 + CloudFront
- Configured your AWS CLI with correct credentials. See AWS CLI Configuration basics for reference.
- Bootstrap CDK project in your AWS account if you have not done so already. See CDK Bootstrapping docs for reference.
- Install project dependencies:
npm ci. - Check environment configuration in
./config/dev.yamlfor developnet environment. Use./config/prod.yamlfor production. - Deploy Common stack:
cdk deploy -c env=dev devCommonStack - Deploy Database stack
cdk deploy -c env=dev devDatabaseStack - Deploy other stack/s of your choice:
- single stack:
cdk deploy -c env=dev devCommonStack. - several stacks:
cdk deploy -c env=dev devDatabaseApiStack, devAdminApiStack.
- single stack:
This project assumes that root hosted zone i.e. crowd.bible already exists in the AWS account.
If you also need to create a subdomain for environment, i.e. dev.crowd.bible, please make sure ./config/dev.yaml includes the following:
# Env domain setup
createEnvHostedZone: true
rootDomainName: 'crowd.bible'
envDomainName: 'dev.crowd.bible'If you don't plan to use subdomains and want to add records to the root hosted zone directly, i.e. api.crowd.bible, please make sure ARR of ACM certificate for the root domain is provided:
# Env domain setup
createEnvHostedZone: false
rootDomainName: 'crowd.bible'
rootDomainCertArn: 'arn:aws:acm:us-east-2:579742570368:certificate/000000000'npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation templatecdk context --clearclear values stored in localcdk.context.json. Useful if deployment fails with "resource not found" kind of error.
- Add API configuration into
./config/dev.yaml. SeedatabaseApiconfig for example. - Add new
ApiServiceStackinto./bin/app.ts. SeedatabaseApiStackfor example. - Deploy API using
cdk deploy -c env=dev <NEW_API_STACK_NAME>
- Add frontend configuration into
./config/dev.yaml. SeeshowcaseAppconfig for example. - Add new
ApiServiceStackinto./bin/app.ts. SeeshowcaseAppStackfor example. - Deploy frontend using
cdk deploy -c env=dev <NEW_FRONTEND_STACK_NAME>
a. example for dev env:npx cdk deploy -c env=dev devDocsStack
List all policies:
aws logs describe-resource-policies
Delete some policies:
aws logs delete-resource-policy --policy-name devNotificationsApiStacknotificationsApiFargateTaskDefnotificationsApiContainerLogGroupPolicyB30998C8
Put a policy to grant access for all services:
aws logs put-resource-policy --policy-name devFargateTaskDefContainerLogGroupPolicyAllServices --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "808019037620" }, "Action": ["logs:CreateLogStream", "logs:PutLogEvents"], "Resource": "arn:aws:logs:us-east-2:808019037620:log-group:/ecs/*" } ] }'