logo
Menu

Amazon CodeCatalyst workflow for Amazon ECS

Example CodeCatalyst workflow to build and publish a container image, and the deploy it to ECS.

Kowsalya Jaganathan
Kowsalya Jaganathan
Amazon Employee
Published May 5, 2023

💻 Examples of
⏰ Last Updated
2023-05-05

This snippet shows a CodeCatalyst workflow that will build and publish a container images, and then deploy it to an ECS cluster.

Used in:

The following values need to replaced in the snippet below:

  • <ECS cluster ARN>
  • <Account-Id>
  • <CodeCatalystPreviewDevelopmentAdministrator role>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Name: BuildAndDeployToECS
SchemaVersion: "1.0"

# Optional - Set automatic triggers.
Triggers:
- Type: Push
Branches:
- main

# Required - Define action configurations.
Actions:
Build_application:
Identifier: aws/build@v1
Inputs:
Sources:
- WorkflowSource
Variables:
- Name: region
Value: us-west-2
- Name: registry
Value: <Account-Id>.dkr.ecr.us-west-2.amazonaws.com
- Name: image
Value: my-respository-cdkecsinfrastack
Outputs:
AutoDiscoverReports:
Enabled: false
Variables:
- IMAGE
Compute:
Type: EC2
Environment:
Connections:
- Role: <CodeCatalystPreviewDevelopmentAdministrator role>
# Add account id within quotes. Eg: "123456789012"
Name: "<Account-Id>"
Name: Non-prod
Configuration:
Steps:
- Run: export account=`aws sts get-caller-identity --output text | awk '{ print $1 }'`
- Run: aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${registry}
- Run: docker build -t appimage .
- Run: docker tag appimage ${registry}/${image}:${WorkflowSource.CommitId}
- Run: docker push --all-tags ${registry}/${image}
- Run: export IMAGE=${registry}/${image}:${WorkflowSource.CommitId}
RenderAmazonECStaskdefinition:
Identifier: aws/ecs-render-task-definition@v1
Configuration:
image: ${Build_application.IMAGE}
container-name: MyContainer
task-definition: task.json
Outputs:
Artifacts:
- Name: TaskDefinition
Files:
- task-definition*
DependsOn:
- Build_application
Inputs:
Sources:
- WorkflowSource
DeploytoAmazonECS:
Identifier: aws/ecs-deploy@v1
Configuration:
task-definition: /artifacts/DeploytoAmazonECS/TaskDefinition/${RenderAmazonECStaskdefinition.task-definition}
service: MyWebApp
cluster: <ECS cluster ARN>
region: us-west-2
Compute:
Type: EC2
Fleet: Linux.x86-64.Large
Environment:
Connections:
- Role: <CodeCatalystPreviewDevelopmentAdministrator role>
# Add account id within quotes. Eg: "12345678"
Name: "<Account Id>"
Name: Non-Prod
DependsOn:
- RenderAmazonECStaskdefinition
Inputs:
Artifacts:
- TaskDefinition
Sources:
- WorkflowSource