Git Product home page Git Product logo

cdk-fargate-docker-starter's Introduction

CDK Fargate Docker starter kit with AWS CDK v2.0

This repository shows an example of how to deploy a simple docker image to a Fargate cluster using AWS CDK.

Read more of CDK at https://docs.aws.amazon.com/CDK/latest/userguide/what-is.html

Features:

  • AWS CDK v2.0 using aws-cdk-lib
  • Fargate cluster with multiple availability zones
  • Nginx server serving static site (just an example of a docker image)
  • Running multiple containers on different context paths
  • Host header or path pattern matching for routing
  • Fixed response for unrouted requests
  • Pass environment variables/parameters to containers
  • Configure a domain name with a TLS certificate and a HTTPS listener for the service
  • Application load balancer (ALB) redirect from HTTP to the HTTPS endpoint
  • Logging
  • Resource tagging

Configure required AWS account

Check that your AWS account is configured. Assume the role in the shell:

# Install from https://github.com/remind101/assume-role
eval $(assume-role your-aws-role)

Initial setup

First you need to have the needed build tools and the AWS CDK installed. After everything is installed you can bootstrap the project on wanted account.

Install dependencies

brew install node awscli
# Install or update CDK globally
npm i -g aws-cdk

Bootstrap the project on a selected account

# Check that the infra can be synthetized
cdk synth

# Initialize the environment
cdk bootstrap aws://account-id/region

Domain and certificate setup

  1. Create a hosted zone (domain name) in AWS Route 53.
  2. Use AWS Certificate Manager to create a domain certificate for dev and prod domains.

Take a note of the certificated ARN's that are needed for the deployment.

Initial deployment

Check that the stack builds.

npm run build

Bootstrap the account.

cdk bootstrap aws://<account>/eu-west-1 -c certificateIdentifier=e3da8de9-ec36-4c75-addd-cc62701eac3a -c domainName=olmi.be -c subdomainName=site-dev -c environment=dev

Deploy the dev version

cdk deploy -c certificateIdentifier=e3da8de9-ec36-4c75-addd-cc62701eac3a -c domainName=olmi.be -c subdomainName=site-dev -c environment=dev

Change the parameters to deploy a prod version:

cdk deploy -c certificateIdentifier=2ff0d9f4-98be-477a-a29f-86d871d5e31f -c domainName=olmi.be -c subdomainName=site-prod -c environment=prod

Other commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

cdk-fargate-docker-starter's People

Contributors

markusl avatar raimohanska avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.