CodePipeline setup based ECS push event

this article migrated

Precondition

  • must be exist ECS cluster, service, task

Create CodeCommit repository

  • create repository name with

    ${organization-name}---${stage-name}---${project-name}
  • click *'Create file' name as *imagedefinitions.json

# imagedefinitions.json

[
  {
    "name": "${YOUR_TASK_CONTAINER_NAME}",
    "imageUri": "${ECR_REPOSITORY}:${IMAGE_TAG}"
  }
]

Warning: task container name should be exactly the same

Create CodePipeline

  • make new pipeline name *pipeline_${stage}_${project-name}

Source stage

Step1: add ECR

  • click *edit of Source stage

  • click *Add Action

  • select ECR

  • and select your ECR

  • input latest for image tag

  • change action name -> ECR-hook

  • change Variable namespace -> (null in other words replace to empty)

  • change Output artifacts -> ECS-Hook-output > this is very important. if you do not change default value(SourceArtifacts) it will not gonna trigger.

Step2: add CodeCommit stage in source stage

  • click *edit of Source stage

  • click *Add Action

  • input action name -> 'CodeCommit-Hook'

  • action provider -> AWS CodeCommit

  • Respository name -> ${organization-name}---${stage-name}---${project-name}

  • Branch name -> Master

  • Output artifacts -> 'CodeCommit-Hook-output'

if you do not add CodeCommit stage in source stage you will get Error because you don't have *imagedefinitions.json

Invalid action configuration Did not find the image definition file imagedefinitions.json in the input artifacts ZIP file. Verify the file is stored in your pipeline's Amazon S3 artifact bucket:

Build Stage

  • skip this stage

Add Deploy stage

  • select deploy provider *ECS

  • select input artifacts -> CodeCommit-Hook

  • select your cluster name of *cluster name section

  • select your service name of *service name section

Create a CloudWatch Events Rule for an Amazon ECR Source (Console)

References

Tips

Don't forget security group inbound rules of VPC

Load balancer forward rule

LB will get 80 and will automatically forward to TG opened port

if Task fail to run automatically pull new image

force service,

CodePipeline with ECR

I'm trying to setup CodePipeline

here is situations

-source stage

---gitlab will push image to ECR ---CodeCommit will provide imagedefinitions.json

-deploy stage

---will deploy to ECS

and I set it up cloud watch event hook https://docs.aws.amazon.com/codepipeline/latest/userguide/create-cwe-ecr-source-console.html

when I click 'release change' it works

but the thing is when I push image to ECR

CodePipeline do nothing

source stage

s3 action -> source as s3

  • code pipeline actions automatically generate CloudWatchRoles per each action

S3-Hook

  • Output artifacts should input

imagedefinitions

s3 versioning required for *S3-hook

Last updated

Was this helpful?