# CodeDeploy

Source: /aws/services/codedeploy/

## Introduction

CodeDeploy is a service that automates application deployments.
On AWS, it supports deployments to Amazon EC2 instances, on-premises instances, serverless Lambda functions, or Amazon ECS services.
Furthermore, based on the target it is also possible to use an in-place deployment or a blue/green deployment.

LocalStack supports a mocking of CodeDeploy API operations.
The supported operations are listed on the [API Coverage section](#api-coverage).

## Getting Started

This guide will walk through the process of creating CodeDeploy applications, deployment configuration, deployment groups, and deployments.

Basic knowledge of the AWS CLI and the [`lstk aws`](/aws/developer-tools/running-localstack/lstk/cloud-and-iac-commands/#aws) command is expected.

Start LocalStack using your preferred method.

### Applications

An application is a CodeDeploy construct that uniquely identifies your targetted application.
Create an application with the [CreateApplication](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateApplication.html) operation:

```bash
lstk aws deploy create-application --application-name hello --compute-platform Server
```

```bash title="Output"
{
    "applicationId": "063714b6-f438-4b90-bacb-ce04af7f5e83"
}
```

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).

```bash
lstk aws deploy get-application --application-name hello
```

```bash title="Output"
{
    "application": {
        "applicationId": "063714b6-f438-4b90-bacb-ce04af7f5e83",
        "applicationName": "hello",
        "createTime": 1747663397.271634,
        "computePlatform": "Server"
    }
}
```

You can list all application using [ListApplications](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListApplications.html).

```bash
lstk aws deploy list-applications
```

```bash title="Output"
{
    "applications": [
        "hello"
    ]
}
```

### Deployment configuration

A deployment configuration consists of rules for deployment along with success and failure criteria.

Create a deployment configuration using [CreateDeploymentConfig](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeploymentConfig.html):

```bash
lstk aws deploy create-deployment-config --deployment-config-name hello-conf \
    --compute-platform Server  \
    --minimum-healthy-hosts '{"type": "HOST_COUNT", "value": 1}'
```

```bash title="Output"
{
    "deploymentConfigId": "0327ce0a-4637-4884-8899-49af7b9423b6"
}
```

[ListDeploymentConfigs](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeploymentConfigs.html) can be used to list all available configs:

```bash
lstk aws deploy list-deployment-configs
```

```bash title="Output"
{
    "deploymentConfigsList": [
        "hello-conf"
    ]
}
```

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.

```bash
lstk aws deploy get-deployment-config --deployment-config-name hello-conf
```

```bash title="Output"
{
    "deploymentConfigInfo": {
        "deploymentConfigId": "0327ce0a-4637-4884-8899-49af7b9423b6",
        "deploymentConfigName": "hello-conf",
        "minimumHealthyHosts": {
            "type": "HOST_COUNT",
            "value": 1
        },
        "createTime": 1747663716.208291,
        "computePlatform": "Server"
    }
}
```

### Deployment groups

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)
- [DeleteDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeleteDeploymentGroup.html)

Create a deployment group with [CreateDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeploymentGroup.html):

```bash
lstk aws deploy create-deployment-group \
    --application-name hello \
    --service-role-arn arn:aws:iam::000000000000:role/role \
    --deployment-group-name hello-group
```

```bash title="Output"
{
    "deploymentGroupId": "09506586-9ba9-4005-a1be-840407abb39d"
}
```

List all deployment groups for an application with [ListDeploymentGroups](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeploymentGroups.html):

```bash
lstk aws deploy list-deployment-groups --application-name hello
```

```bash title="Output"
{
    "deploymentGroups": [
        "hello-group"
    ]
}
```

Get a deployment group with [GetDeploymentGroup](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetDeploymentGroup.html):

```bash
lstk aws deploy get-deployment-group --application-name hello \
    --deployment-group-name hello-group
```

```bash title="Output"
{
    "deploymentGroupInfo": {
        "applicationName": "hello",
        "deploymentGroupId": "09506586-9ba9-4005-a1be-840407abb39d",
        "deploymentGroupName": "hello-group",
        "deploymentConfigName": "CodeDeployDefault.OneAtATime",
        "autoScalingGroups": [],
        "serviceRoleArn": "arn:aws:iam::000000000000:role/role",
        "triggerConfigurations": [],
        "deploymentStyle": {
            "deploymentType": "IN_PLACE",
            "deploymentOption": "WITHOUT_TRAFFIC_CONTROL"
        },
        "outdatedInstancesStrategy": "UPDATE",
        "computePlatform": "Server",
        "terminationHookEnabled": false
    }
}
```

### Deployments

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)

Create a deployment with [CreateDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeployment.html):

```bash
lstk aws deploy create-deployment \
    --application-name hello \
    --deployment-group-name hello-group \
    --revision '{"revisionType": "S3", "s3Location": {"bucket": "placeholder", "key": "placeholder", "bundleType": "tar"}}'
```

```bash title="Output"
{
    "deploymentId": "d-TU3TNCSTO"
}
```

List all deployments for an application with [ListDeployments](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ListDeployments.html):

```bash
lstk aws deploy list-deployments
```

```bash title="Output"
{
    "deployments": [
        "d-TU3TNCSTO"
    ]
}
```

Get a deployment with [GetDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_GetDeployment.html):

```bash
lstk aws deploy get-deployment --deployment-id d-TU3TNCSTO
```

```bash title="Output"
{
    "deploymentInfo": {
        "applicationName": "hello",
        "deploymentGroupName": "hello-group",
        "deploymentConfigName": "CodeDeployDefault.OneAtATime",
        "deploymentId": "d-TU3TNCSTO",
        "revision": {
            "revisionType": "S3",
            "s3Location": {
                "bucket": "placeholder",
                "key": "placeholder",
                "bundleType": "tar"
            }
        },
        "status": "Created",
        "createTime": 1747750522.133381,
        "creator": "user",
        "ignoreApplicationStopFailures": false,
        "updateOutdatedInstancesOnly": false,
        "deploymentStyle": {
            "deploymentType": "IN_PLACE",
            "deploymentOption": "WITHOUT_TRAFFIC_CONTROL"
        },
        "instanceTerminationWaitTimeStarted": false,
        "fileExistsBehavior": "DISALLOW",
        "deploymentStatusMessages": [],
        "computePlatform": "Server"
    }
}
```

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:

Continue a deployment with [ContinueDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_StopDeployment.html):

```bash
lstk aws deploy continue-deployment --deployment-id d-TU3TNCSTO
```

Stop a deployment with [StopDeployment](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_StopDeployment.html):

```bash
lstk aws deploy stop-deployment --deployment-id d-TU3TNCSTO
```

```bash title="Output"
{
    "status": "Succeeded",
    "statusMessage": "Mock deployment stopped"
}
```

## Limitations

All CodeDeploy operations are currently mocked.

## API Coverage


### codedeploy API coverage

Source service: `codedeploy`. 25 of 47 tracked operations are implemented.

Service documentation: /aws/services/codedeploy/
License availability: available starting with the Ultimate plan. See /aws/licensing/ for current plan details.

| Operation | Status |
| --- | --- |
| AddTagsToOnPremisesInstances | Not implemented |
| BatchGetApplicationRevisions | Not implemented |
| BatchGetApplications | Implemented |
| BatchGetDeploymentGroups | Not implemented |
| BatchGetDeploymentInstances | Not implemented |
| BatchGetDeploymentTargets | Not implemented |
| BatchGetDeployments | Implemented |
| BatchGetOnPremisesInstances | Not implemented |
| ContinueDeployment | Implemented |
| CreateApplication | Implemented |
| CreateDeployment | Implemented |
| CreateDeploymentConfig | Implemented |
| CreateDeploymentGroup | Implemented |
| DeleteApplication | Implemented |
| DeleteDeploymentConfig | Implemented |
| DeleteDeploymentGroup | Implemented |
| DeleteGitHubAccountToken | Not implemented |
| DeleteResourcesByExternalId | Not implemented |
| DeregisterOnPremisesInstance | Not implemented |
| GetApplication | Implemented |
| GetApplicationRevision | Not implemented |
| GetDeployment | Implemented |
| GetDeploymentConfig | Implemented |
| GetDeploymentGroup | Implemented |
| GetDeploymentInstance | Not implemented |
| GetDeploymentTarget | Not implemented |
| GetOnPremisesInstance | Not implemented |
| ListApplicationRevisions | Not implemented |
| ListApplications | Implemented |
| ListDeploymentConfigs | Implemented |
| ListDeploymentGroups | Implemented |
| ListDeploymentInstances | Not implemented |
| ListDeploymentTargets | Not implemented |
| ListDeployments | Implemented |
| ListGitHubAccountTokenNames | Not implemented |
| ListOnPremisesInstances | Not implemented |
| ListTagsForResource | Implemented |
| PutLifecycleEventHookExecutionStatus | Implemented |
| RegisterApplicationRevision | Not implemented |
| RegisterOnPremisesInstance | Not implemented |
| RemoveTagsFromOnPremisesInstances | Not implemented |
| SkipWaitTimeForInstanceTermination | Not implemented |
| StopDeployment | Implemented |
| TagResource | Implemented |
| UntagResource | Implemented |
| UpdateApplication | Implemented |
| UpdateDeploymentGroup | Implemented |
