|
| 1 | +--- |
| 2 | +title: CodeDeploy |
| 3 | +linkTitle: CodeDeploy |
| 4 | +description: > |
| 5 | + Get started with CodeDeploy on LocalStack |
| 6 | +tags: ["Pro image"] |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +CodeDeploy is a service that automates application deployments. |
| 12 | +On AWS, it supports deployments to Amazon EC2 instances, on-premises instances, serverless Lambda functions, or Amazon ECS services. |
| 13 | +Furthermore, based on the target it is also possible to use an in-place deployment or a blue/green deployment. |
| 14 | + |
| 15 | +LocalStack supports a mocking of CodeDeploy API operations. |
| 16 | +The supported operations are listed on the [API coverage page]({{< ref "coverage_codedeploy" >}}). |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +This guide will walk through the process of creating CodeDeploy applications, deployment configuration, deployment groups, and deployments. |
| 21 | + |
| 22 | +Basic knowledge of the AWS CLI and the [`awslocal`](https://github.com/localstack/awscli-local) wrapper is expected. |
| 23 | + |
| 24 | +Start LocalStack using your preferred method. |
| 25 | + |
| 26 | +### Applications |
| 27 | + |
| 28 | +An application is a CodeDeploy construct that uniquely identifies your targetted application. |
| 29 | +Create an application with the [CreateApplication](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateApplication.html) operation: |
| 30 | + |
| 31 | +{{< command >}} |
| 32 | +$ awslocal deploy create-application --application-name hello --compute-platform Server |
| 33 | +<disable-copy> |
| 34 | +{ |
| 35 | + "applicationId": "063714b6-f438-4b90-bacb-ce04af7f5e83" |
| 36 | +} |
| 37 | +</disable-copy> |
| 38 | +{{< /command >}} |
| 39 | + |
| 40 | +Make note of the application name, which can be used with other operations such as [GetApplication](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetApplication.html), [UpdateApplication](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_UpdateApplication.html) and [DeleteApplication](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeleteApplication.html). |
| 41 | + |
| 42 | +{{< command >}} |
| 43 | +$ awslocal deploy get-application --application-name hello |
| 44 | +<disable-copy> |
| 45 | +{ |
| 46 | + "application": { |
| 47 | + "applicationId": "063714b6-f438-4b90-bacb-ce04af7f5e83", |
| 48 | + "applicationName": "hello", |
| 49 | + "createTime": 1747663397.271634, |
| 50 | + "computePlatform": "Server" |
| 51 | + } |
| 52 | +} |
| 53 | +</disable-copy> |
| 54 | +{{< /command >}} |
| 55 | + |
| 56 | +You can list all application using [ListApplications](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListApplications.html). |
| 57 | + |
| 58 | +{{< command >}} |
| 59 | +$ awslocal deploy list-applications |
| 60 | +<disable-copy> |
| 61 | +{ |
| 62 | + "applications": [ |
| 63 | + "hello" |
| 64 | + ] |
| 65 | +} |
| 66 | +</disable-copy> |
| 67 | +{{< /command >}} |
| 68 | + |
| 69 | +### Deployment configuration |
| 70 | + |
| 71 | +A deployment configuration consists of rules for deployment along with success and failure criteria. |
| 72 | + |
| 73 | +Create a deployment configuration using [CreateDeploymentConfig](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeploymentConfig.html): |
| 74 | + |
| 75 | +{{< command >}} |
| 76 | +$ awslocal deploy create-deployment-config --deployment-config-name hello-conf \ |
| 77 | + --compute-platform Server \ |
| 78 | + --minimum-healthy-hosts '{"type": "HOST_COUNT", "value": 1}' |
| 79 | +<disable-copy> |
| 80 | +{ |
| 81 | + "deploymentConfigId": "0327ce0a-4637-4884-8899-49af7b9423b6" |
| 82 | +} |
| 83 | +</disable-copy> |
| 84 | +{{< /command >}} |
| 85 | + |
| 86 | +[ListDeploymentConfigs](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeploymentConfigs.html) can be used to list all available configs: |
| 87 | + |
| 88 | +{{< command >}} |
| 89 | +$ awslocal deploy list-deployment-configs |
| 90 | +<disable-copy> |
| 91 | +{ |
| 92 | + "deploymentConfigsList": [ |
| 93 | + "hello-conf" |
| 94 | + ] |
| 95 | +} |
| 96 | +</disable-copy> |
| 97 | +{{< /command >}} |
| 98 | + |
| 99 | +Use [GetDeploymentConfig](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetDeploymentConfig.html) and [DeleteDeploymentConfig](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeleteDeploymentConfig.html) to manage deployment configurations. |
| 100 | + |
| 101 | +{{< command >}} |
| 102 | +$ awslocal deploy get-deployment-config --deployment-config-name hello-conf |
| 103 | +<disable-copy> |
| 104 | +{ |
| 105 | + "deploymentConfigInfo": { |
| 106 | + "deploymentConfigId": "0327ce0a-4637-4884-8899-49af7b9423b6", |
| 107 | + "deploymentConfigName": "hello-conf", |
| 108 | + "minimumHealthyHosts": { |
| 109 | + "type": "HOST_COUNT", |
| 110 | + "value": 1 |
| 111 | + }, |
| 112 | + "createTime": 1747663716.208291, |
| 113 | + "computePlatform": "Server" |
| 114 | + } |
| 115 | +} |
| 116 | +</disable-copy> |
| 117 | +{{< /command >}} |
| 118 | + |
| 119 | +### Deployment groups |
| 120 | + |
| 121 | +Deployment groups can be managed with [CreateDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeploymentGroup.html), [ListDeploymentGroups](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeploymentGroups.html), [UpdateDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_UpdateDeploymentGroup.html), [GetDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetDeploymentGroup.html) and [DeleteDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeleteDeploymentGroup.html). |
| 122 | + |
| 123 | +{{< command >}} |
| 124 | +$ awslocal deploy create-deployment-group \ |
| 125 | + --application-name hello \ |
| 126 | + --service-role-arn arn:aws:iam::000000000000:role/role \ |
| 127 | + --deployment-group-name hello-group |
| 128 | +<disable-copy> |
| 129 | +{ |
| 130 | + "deploymentGroupId": "09506586-9ba9-4005-a1be-840407abb39d" |
| 131 | +} |
| 132 | +</disable-copy> |
| 133 | +{{< /command >}} |
| 134 | + |
| 135 | +{{< command >}} |
| 136 | +$ awslocal deploy list-deployment-groups --application-name hello |
| 137 | +<disable-copy> |
| 138 | +{ |
| 139 | + "deploymentGroups": [ |
| 140 | + "hello-group" |
| 141 | + ] |
| 142 | +} |
| 143 | +</disable-copy> |
| 144 | +{{< /command >}} |
| 145 | + |
| 146 | +{{< command >}} |
| 147 | +$ awslocal deploy get-deployment-group --application-name hello \ |
| 148 | + --deployment-group-name hello-group |
| 149 | +<disable-copy> |
| 150 | +{ |
| 151 | + "deploymentGroupInfo": { |
| 152 | + "applicationName": "hello", |
| 153 | + "deploymentGroupId": "09506586-9ba9-4005-a1be-840407abb39d", |
| 154 | + "deploymentGroupName": "hello-group", |
| 155 | + "deploymentConfigName": "CodeDeployDefault.OneAtATime", |
| 156 | + "autoScalingGroups": [], |
| 157 | + "serviceRoleArn": "arn:aws:iam::000000000000:role/role", |
| 158 | + "triggerConfigurations": [], |
| 159 | + "deploymentStyle": { |
| 160 | + "deploymentType": "IN_PLACE", |
| 161 | + "deploymentOption": "WITHOUT_TRAFFIC_CONTROL" |
| 162 | + }, |
| 163 | + "outdatedInstancesStrategy": "UPDATE", |
| 164 | + "computePlatform": "Server", |
| 165 | + "terminationHookEnabled": false |
| 166 | + } |
| 167 | +} |
| 168 | +</disable-copy> |
| 169 | +{{< /command >}} |
| 170 | + |
| 171 | +### Deployments |
| 172 | + |
| 173 | +Operations related to deployment management are: [CreateDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeployment.html), [GetDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetDeployment.html), [ListDeployments](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeployments.html). |
| 174 | + |
| 175 | +{{< command >}} |
| 176 | +$ awslocal deploy create-deployment \ |
| 177 | + --application-name hello \ |
| 178 | + --deployment-group-name hello-group \ |
| 179 | + --revision '{"revisionType": "S3", "s3Location": {"bucket": "placeholder", "key": "placeholder", "bundleType": "tar"}}' |
| 180 | +<disable-copy> |
| 181 | +{ |
| 182 | + "deploymentId": "d-TU3TNCSTO" |
| 183 | +} |
| 184 | +</disable-copy> |
| 185 | +{{< /command >}} |
| 186 | + |
| 187 | +{{< command >}} |
| 188 | +$ awslocal deploy list-deployments |
| 189 | +<disable-copy> |
| 190 | +{ |
| 191 | + "deployments": [ |
| 192 | + "d-TU3TNCSTO" |
| 193 | + ] |
| 194 | +} |
| 195 | +</disable-copy> |
| 196 | +{{< /command >}} |
| 197 | + |
| 198 | +{{< command >}} |
| 199 | +$ awslocal deploy get-deployment --deployment-id d-TU3TNCSTO |
| 200 | +<disable-copy> |
| 201 | +{ |
| 202 | + "deploymentInfo": { |
| 203 | + "applicationName": "hello", |
| 204 | + "deploymentGroupName": "hello-group", |
| 205 | + "deploymentConfigName": "CodeDeployDefault.OneAtATime", |
| 206 | + "deploymentId": "d-TU3TNCSTO", |
| 207 | + "revision": { |
| 208 | + "revisionType": "S3", |
| 209 | + "s3Location": { |
| 210 | + "bucket": "placeholder", |
| 211 | + "key": "placeholder", |
| 212 | + "bundleType": "tar" |
| 213 | + } |
| 214 | + }, |
| 215 | + "status": "Created", |
| 216 | + "createTime": 1747750522.133381, |
| 217 | + "creator": "user", |
| 218 | + "ignoreApplicationStopFailures": false, |
| 219 | + "updateOutdatedInstancesOnly": false, |
| 220 | + "deploymentStyle": { |
| 221 | + "deploymentType": "IN_PLACE", |
| 222 | + "deploymentOption": "WITHOUT_TRAFFIC_CONTROL" |
| 223 | + }, |
| 224 | + "instanceTerminationWaitTimeStarted": false, |
| 225 | + "fileExistsBehavior": "DISALLOW", |
| 226 | + "deploymentStatusMessages": [], |
| 227 | + "computePlatform": "Server" |
| 228 | + } |
| 229 | +} |
| 230 | +</disable-copy> |
| 231 | +{{< /command >}} |
| 232 | + |
| 233 | +Furthermore, [ContinueDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_StopDeployment.html) and [StopDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_StopDeployment.html) can be used to control the deployment flows. |
| 234 | + |
| 235 | +{{< command >}} |
| 236 | +$ awslocal deploy continue-deployment --deployment-id d-TU3TNCSTO |
| 237 | +{{< /command >}} |
| 238 | + |
| 239 | +{{< command >}} |
| 240 | +$ awslocal deploy stop-deployment --deployment-id d-TU3TNCSTO |
| 241 | +<disable-copy> |
| 242 | +{ |
| 243 | + "status": "Succeeded", |
| 244 | + "statusMessage": "Mock deployment stopped" |
| 245 | +} |
| 246 | +</disable-copy> |
| 247 | +{{< /command >}} |
| 248 | + |
| 249 | +## Limitations |
| 250 | + |
| 251 | +All CodeDeploy operations are currently mocked. |
0 commit comments