Repository for In The Loop demo for CDK - Fargate
- AWS Account
- AWS CLI (with Credentials)
- Docker
- NPM
- TypeScript (npm -g install typescript)
- dotnet
Build:
> dotnet build .\Api.Service.csproj
Run
> dotnet run .\Api.Service.csproj
Build an Image of the container
> docker build -t apiservice .
Run an instance of the image
> docker run -d -p 5001:80 --name api apiservice
Login to Bash of the running container
> docker exec -it api /bin/bash
GET http://localhost:5001/api/ping?request=1
We need to push our Docker Image (apiservice) to ECR in AWS. For that we need to create a repository in ECR. To create the repository, we will use CDK.
-
Workshop: http://cdkworkshop.com/
-
Api Reference: https://docs.aws.amazon.com/cdk/api/latest/
Install CDK
> npm install -g aws-cdk
Initialize CDK Project
> cdk init -a ecr-stack -l typescript
Compile the Project
> npm run build
List Stacks in the CDK Project
> cdk ls
Npm Package: @aws-cdk/aws-ecr
Synthesize CDK to ensure cdk is able to convert code into yaml
> cdk synth EcrRepoStack
Do a DIFF against an environment to see what is the difference b/w local and account.
> cdk diff EcrRepoStack --profile devops
Deploy the stack
> cdk deploy EcrRepoStack --profile devops
Push the Docker Image to ECR Repository using AWS Credentials
Get a docker Login for ECR
> aws ecr get-login --no-include-email --region ap-southeast-2
User docker to login to AWS-ECR
> docker login -u AWS -p eyJwYXlsb2FkIjoiRjNIWmg4NWovRFdmQmVrR1dJN01....
Build the Image
> docker build -t api-service-repository .
Give the build Image the ECR Tag
> docker tag api-service-repository:latest 19XXXXXXXXX7.dkr.ecr.ap-southeast-2.amazonaws.com/api-service-repository:latest
Push the Tagged Image to ECR
> docker push 19XXXXXXXXX7.dkr.ecr.ap-southeast-2.amazonaws.com/api-service-repository:latest
- @aws-cdk/aws-ecr
- @aws-cdk/aws-ec2
- @aws-cdk/aws-ecs
- @aws-cdk/aws-elasticloadbalancingv2
- @aws-cdk/aws-logs