This Project is a boiler plate for running a secure nodejs webapp through ECS using Fargate with CDK.
A backend is provided through GraphQL AppSync.
Configure your aws-cli and CDK
Be sure how you know how run CDK in context
The graphQL stack creates an Aurora DB instance that interfaces with AppSync GraphQL for saving and retrieving data.
Build GraphQL Stack first to set API Key and GraphQL URL in param store
cdk deploy GraphQLStack -c domain=<sub.yourdomain.com> -c aws-access-key=$(aws configure get aws_access_key_id) -c aws-secret-access-key=$(aws configure get aws_secret_access_key) -c region=eu-west-1
The webapp stack runs a simple NodeJS server instance with micro-service which consumes the graphql endpoint. The app is loadbalanced with its container hosted on Fargate and protected using WAF rules.
Build WebappStack that provides the secrets to allow aws cli to retrieve params set in AppSync GraphQL Stack
cdk deploy WebappStack -c domain=<sub.yourdomain.com> -c aws-access-key=$(aws configure get aws_access_key_id) -c aws-secret-access-key=$(aws configure get aws_secret_access_key) -c region=eu-west-1
The cdk.json
file tells the CDK Toolkit how to execute your app.
Register or transfer a domain using Route53.
Follow the steps to create a Hosted Zone
Tip:
Create accounts for development/testing/production
I wished to have some sub-domains for various development/testing and production environment so this tutorial helped set that up!
Uses the CDK method DnsValidatedCertificate
which authorizes your certificates without having to manually approve.
This requires the previous step completed for domains in Route53.
WebappStack is deployed to ECS and the task is run based on the Dockerfile in the simple
directory.
This application uses the ECS Patterns for an application load balanced fargatge service
TODO
TODO
To run the Webapp with GraphQL instances locally with Docker:
- Deploy the GraphQL stack as described above
- Change directory to the simple application
cd simple
- Export the required variables used by the Docker instance
$ export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
$ export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)
- Build the docker image providing the new env variables e.g.
$ docker build --build-arg AWS_ACCESS_KEY_ID --build-arg AWS_SECRET_ACCESS_KEY .
- Get the latest docker image id
$ docker image ls
- Run the latest image id and bind port 3000
$ docker run -p 3000:3000 <docker image id from step 5>
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy -c domain=<INSERT DOMAIN NAME HERE>
deploy this stack to your default AWS account/region, providing a domain namecdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template