Amazon ECS Blue/Green deployment on Codepipeline

Photo by T K on Unsplash

Amazon ECS Blue/Green deployment on Codepipeline

AWS/AWS CodePipeline

  • requirement
two ELB Target Group
ECS service >> Deployment Type >> Blue green deployment (With CodeDeploy)
AWS CodeDeploy application
AWS CodeDeploy Deployment group
taskdef.json
appspec.yaml
CodeDeploy
  • ECS service
Deployment Type
>> Blue green deployment (With CodeDeploy)
>>> create AWS CodeDeploy application
>>> create AWS CodeDeploy Deployment group
  • taskdef.json
{
  "executionRoleArn":"<use-your-role",
  "containerDefinitions": [{
    "name": "<use-your-container-name>",
    "image": "<use-your-container-image>",
    "logConfiguration": { 
    "logDriver": "awslogs",
        "options": { 
            "awslogs-group" : "/ecs/fargate-task-definition",
            "awslogs-region": "<your-region>",
            "awslogs-stream-prefix": "ecs"
        }
    },
    "essential": true,
    "portMappings": [{
      "hostPort": <use-your-port>,
      "protocol": "<use-your-protocol>",
      "containerPort": <use-your-port>
    }]
  }],
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "networkMode": "awsvpc",
  "cpu": "1024",
  "memory": "2048",
  "family": "<use-your-taskdefinition-name>"
}
  • appspec.yaml
version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: "<use-your-container-name>"
          ContainerPort: <use-your-port>
        PlatformVersion: "LATEST"
  • CodeDeploy
Action name >> Deploy
Action provider >> Amazon ECS (Blue/Green)
Region >> <your-region>
Input artifacts >> SourceArtifact
AWS CodeDeploy application name >> <your-codedeploy-app-name>
AWS CodeDeploy deployment group >> <your-codedeploy-group-name>
Amazon ECS task definition >> SourceArtifact // taskdef-dev.json
AWS CodeDeploy AppSpec file >> SourceArtifact // appspec-dev.yaml