1. circleci/aws-ecs@6.0.2

circleci/aws-ecs@6.0.2

Certified
Sections
Manage and deploy apps via Amazon's AWS Elastic Container Service (ECS) on CircleCI. Supports the EC2 and Fargate launch types and Blue/Green deployment via CodeDeploy.
Created: December 4, 2018Version Published: November 21, 2024Releases: 50
Org Usage:
1190

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: aws-ecs: circleci/aws-ecs@6.0.2

Use aws-ecs elements in your existing workflows and jobs.

Usage Examples

deploy_ecs_scheduled_task

Use the AWS CLI and this orb to deploy an ECS Scheduled Task Rule after updating a task definition. The update_task_definition or update_task_definition_from_json command must be run first.

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 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: deploy_scheduled_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: us-east-1 role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: '3600' - aws-ecs/update_task_definition_from_json: region: us-east-1 task_definition_json: my-app-definition.json - aws-ecs/deploy_ecs_scheduled_task: region: us-east-1 rule_name: example-rule workflows: deploy: jobs: - deploy_scheduled_task: context: - CircleCI_OIDC_Token

deploy_service_update

Update an ECS service using OIDC for authentication. Import the aws-cli orb and authenticate using the aws-cli/setup command with a valid role_arn for OIDC authentication.

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 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecr: circleci/aws-ecr@9.3.4 aws-ecs: circleci/aws-ecs@6.0.0 workflows: build-and-deploy: jobs: - aws-ecr/build_and_push_image: auth: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECR_ROLE profile_name: OIDC-USER region: AWS_REGION repo: ${MY_APP_PREFIX} tag: ${CIRCLE_SHA1} - aws-ecs/deploy_service_update: auth: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE cluster: ${MY_APP_PREFIX}-cluster container_image_name_updates: container=${MY_APP_PREFIX}-service,tag=${CIRCLE_SHA1} family: ${MY_APP_PREFIX}-service profile_name: OIDC-USER region: us-east-1 requires: - aws-ecr/build_and_push_image

run_task_ec2

Start the run of an ECS task on EC2.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: awsvpc: false cluster: cluster1 launch_type: EC2 region: us-east-1 task_definition: myapp workflows: run_task: jobs: - run_task

run_task_fargate

Start the run of an ECS task on Fargate.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: cluster: cluster1 region: us-east-1 security_group_ids: $SECURITY_GROUP_IDS subnet_ids: $SUBNET_ONE, $SUBNET_TWO task_definition: myapp workflows: run_task: jobs: - run_task

run_task_fargate_spot

Amazon Fargate Spot Instances let you take advantage of spare compute capacity in the AWS Cloud at steep discounts. Fargate Spot is an AWS Fargate capability that can run interruption-tolerant Amazon Elastic Container Service (Amazon ECS) tasks at up to a 70% discount off the Fargate price. Since tasks can still be interrupted, only fault tolerant applications are suitable for Fargate Spot. CircleCI provides continuous integration and delivery for any platform, as well as your own infrastructure. CircleCI can automatically trigger low-cost, serverless tasks with AWS Fargate Spot in Amazon ECS.

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 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: capacity_provider_strategy: >- capacityProvider=FARGATE,weight=1 capacityProvider=FARGATE_SPOT,weight=1 cluster: $CLUSTER_NAME launch_type: '' region: us-east-1 security_group_ids: $SECURITY_GROUP_IDS_FETCHED subnet_ids: $SUBNET_ONE, $SUBNET_TWO task_definition: $My_Task_Def workflows: run_task: jobs: - run_task

update_service

Use the AWS CLI and this orb to update an ECS service. (Supports both EC2 and Fargate launch types)

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 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: update-tag: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: '3600' - aws-ecs/update_service: cluster: ${MY_APP_PREFIX}-cluster container_image_name_updates: container=${MY_APP_PREFIX}-service,tag=stable family: ${MY_APP_PREFIX}-service region: us-east-1 workflows: deploy: jobs: - update-tag: context: - CircleCI_OIDC_Token

update_task_definition_from_json

Use the AWS CLI and this orb to create a new ECS task definition based upon a local JSON file.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: update-tag: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: '3600' - aws-ecs/update_task_definition_from_json: region: us-east-1 task_definition_json: my-app-definition.json workflows: deploy: jobs: - update-tag: context: - CircleCI_OIDC_Token

verify_revision_deployment

Verify the deployment of an ECS revision.

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 version: '2.1' orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: verify-deployment: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: '3600' - run: command: > TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ --task_definition ${MY_APP_PREFIX}-service \ --output text \ --query 'taskDefinition.taskDefinitionArn' \ --profile default \ --region ${AWS_DEFAULT_REGION}) echo "export TASK_DEFINITION_ARN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV name: Get last task definition - aws-ecs/verify_revision_is_deployed: cluster: ${MY_APP_PREFIX}-cluster family: ${MY_APP_PREFIX}-service region: us-east-1 task_definition_arn: ${TASK_DEFINITION_ARN} workflows: test-workflow: jobs: - verify-deployment: context: - CircleCI_OIDC_Token

Jobs

deploy_service_update

Install AWS CLI and update the ECS service with the registered task definition.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
auth
The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
Yes
-
steps
cluster
The short name or full ARN of the cluster that hosts the service.
Yes
-
string
codedeploy_application_name
The name of the AWS CodeDeploy application used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_capacity_provider_base
The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and capacity-provider-weight.
No
''
string
codedeploy_capacity_provider_name
The name of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with capacity-provider-base and capacity-provider-weight.
No
''
string
codedeploy_capacity_provider_weight
The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and capacity-provider-base.
No
''
string
codedeploy_deployment_group_name
The name of the AWS CodeDeploy deployment group used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_load_balanced_container_name
The name of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_load_balanced_container_port
The port of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
'80'
string
container_docker_label_updates
Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas.
No
''
string
container_env_var_updates
Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas.
No
''
string
container_image_name_updates
Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used.
No
''
string
container_secret_updates
Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas.
No
''
string
deployment_config_name
The name of a CODE DEPLOY deployment configuration associated with the IAM user or AWS account. If not specified, the value configured in the deployment group is used as the default.
No
''
string
deployment_controller
The deployment controller to use for the service. Defaulted to ECS
No
ECS
enum
enable_circuit_breaker
Determines whether a service deployment will fail if the service can’t reach a steady state. The deployment circuit breaker can only be used for services using the rolling update (ECS ) deployment type.
No
false
boolean
executor
The executor to use for this job. By default, this will use the "default" executor provided by this orb.
No
default
executor
fail_on_verification_timeout
Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts. Only in use when verify_revision_is_deployed is set to true.
No
true
boolean
family
Name of the task definition's family.
Yes
-
string
force_new_deployment
Whether to force a new deployment of the service. Not applicable to ECS services that are of the Blue/Green Deployment type.
No
false
boolean
max_poll_attempts
The maximum number of attempts to poll the deployment status before giving up. Only in use when verify_revision_is_deployed is set to true.
No
50
integer
poll_interval
The polling interval, in seconds. Only in use when verify_revision_is_deployed is set to true.
No
20
integer
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
${AWS_DEFAULT_REGION}
string
service_name
The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition.
No
''
string
skip_task_definition_registration
Whether to skip registration of a new task definition.
No
false
boolean
task_definition_tags
The metadata that you apply to the task definition to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. (Existing environment variables not included in this parameter will not be removed) Expected formats: - Shorthand Syntax key=string,value=string ... - JSON Syntax [{"key": "string","value": "string"} ... ] Values should not contain commas.
No
''
string
verification_timeout
The maximum amount of time to wait for a blue/green deployment to complete before timing out. Only in use when the deployment controller is the blue/green deployment type.
No
10m
string
verify_revision_is_deployed
Runs the verify_revision_is_deployed Orb command to verify that the revision has been deployed and is the only deployed revision for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached.
No
false
boolean

run_task

Install AWS CLI and Start a new ECS task using the specified task definition and other parameters.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
assign_public_ip
"Assign a public IP or not"
No
DISABLED
enum
auth
The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
Yes
-
steps
awsvpc
"Does your task definition use awsvpc mode or not. If so, this should be true and you should also include subnet_ids and optionally security_group_ids / assign_public_ips."
No
true
boolean
capacity_provider_strategy
The capacity provider strategy to use for the task. If a `capacity_provider_strategy` is specified, the `launch_type` parameter must be set to an empty string.
No
''
string
cluster
The name or ARN of the cluster on which to run the task.
Yes
-
string
count
"The number of instantiations of the specified task to place on your cluster. You can specify up to 10 tasks per call."
No
1
integer
enable_ecs_managed_tags
"Specifies whether to enable Amazon ECS managed tags for the task."
No
false
boolean
enable_execute_command
Determines whether to use the execute command functionality for the containers in this task. If true, this enables execute command functionality on all containers in the task.
No
false
boolean
executor
The executor to use for this job. By default, this will use the "default" executor provided by this orb.
No
default
executor
group
The name of the task group to associate with the task. The default value is the family name of the task definition (for example, family:my_family_name).
No
''
string
launch_type
The launch type on which to run your task. Possible values EC2, FARGATE, or an empty string. For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide.
No
FARGATE
enum
overrides
A list of container overrides in JSON format that specify the name of a container in the specified task definition and the overrides it should receive.
No
''
string
placement_constraints
"An array of placement constraint objects to use for the task. You can specify up to 10 constraints per task (including constraints in the task definition and those specified at runtime). Expected format: type=string,field=string."
No
''
string
placement_strategy
"The placement strategy objects to use for the task. You can specify a maximum of five strategy rules per task. Expected format: type=string,field=string."
No
''
string
platform_version
Use this to specify the platform version that the task should run on. A platform version should only be specified for tasks using the Fargate launch type.
No
''
string
profile_name
AWS profile name to be configured.
No
default
string
propagate_tags
"Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action."
No
false
boolean
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
${AWS_DEFAULT_REGION}
string
run_task_output
Specifies a local json file to save the output logs from the aws ecs run_task command. Use tools like JQ to read and parse this information such as "task-arns" and "task-ids"
No
''
string
security_group_ids
"List of security group ids separated by commas. Expected Format: sg-010a460f7f442fa75,sg-010a420f7faa5fa75"
No
''
string
started_by
An optional tag specified when a task is started. For example, if you automatically trigger a task to run a batch process job, you could apply a unique identifier for that job to your task with the startedBy parameter. You can then identify which tasks belong to that job by filtering the results of a ListTasks call with the startedBy value. Up to 36 letters (uppercase and lowercase), num- bers, hyphens, and underscores are allowed.
No
''
string
subnet_ids
"List of subnet ids separated by commas. Expected Format: subnet-70faa93b,subnet-bcc54b93"
No
''
string
tags
"The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Expected format: key=string,value=string."
No
''
string
task_definition
"The family and revision (family:revision) or full ARN of the task definition to run. If a revision is not specified, the latest ACTIVE revision is used."
Yes
-
string

update_task_definition

Install AWS CLI and register a task definition.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
auth
The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
Yes
-
steps
container_docker_label_updates
Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas.
No
''
string
container_env_var_updates
Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas.
No
''
string
container_image_name_updates
Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used.
No
''
string
container_secret_updates
Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas.
No
''
string
deploy_scheduled_task
Set this parameter to true to deploy updated task definition to a scheduled task rule.
No
false
boolean
executor
The executor to use for this job. By default, this will use the "default" executor provided by this orb.
No
default
executor
family
Name of the task definition's family.
Yes
-
string
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
${AWS_DEFAULT_REGION}
string
rule_name
The name of the scheduled task's rule to update. Must be a valid ECS Rule.
No
''
string

update_task_definition_from_json

Install AWS CLI and a task definition from a json file.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
auth
The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information.
Yes
-
steps
deploy_scheduled_task
Set this parameter to true to deploy updated task definition to a scheduled task rule.
No
false
boolean
executor
The executor to use for this job. By default, this will use the "default" executor provided by this orb.
No
default
executor
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
${AWS_DEFAULT_REGION}
string
rule_name
The name of the scheduled task's rule to update. Must be a valid ECS Rule.
Yes
-
string
task_definition_json
Location of your .json task definition file (relative or absolute).
Yes
-
string

Commands

deploy_ecs_scheduled_task

Deploy an ECS Scheduled Task Rule after updating a task definition. The update_task_definition command must be run first.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
$AWS_DEFAULT_REGION
string
rule_name
The name of the scheduled task's rule to update.
Yes
-
string

install_ecs_cli

Installs the AWS ECS CLI

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
install_dir
Specify the installation directory for the AWS ECS CLI. By default, the installation directory will be /usr/local/bin/ecs-cli.
No
/usr/local/bin/ecs-cli
string
override_installed
By default, if the AWS ECS CLI is detected on the system, the install will be skipped. Enable this to override the installed version and install your specified version.
No
false
boolean
version
Specify the version of the AWS ECS CLI to install. By default, the latest version will be installed.
No
latest
string

run_task

Starts a new ECS task using the specified task definition and other parameters. For more information on ECS Run-Task options, see: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/run_task.html

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
assign_public_ip
Assign a public IP or not
No
DISABLED
enum
awsvpc
Does your task defintion use awsvpc mode or not. If so, this should be true and you should also include subnet_ids and optionally security_group_ids / assign_public_ips.
No
true
boolean
capacity_provider_strategy
The capacity provider strategy to use for the task. If a `capacity_provider_strategy` is specified, the `launch_type` parameter must be set to an empty string.
No
''
string
cluster
The name or ARN of the cluster on which to run the task.
Yes
-
string
count
"The number of instantiations of the specified task to place on your cluster. You can specify up to 10 tasks per call."
No
1
integer
enable_ecs_managed_tags
"Specifies whether to enable Amazon ECS managed tags for the task."
No
false
boolean
enable_execute_command
Determines whether to use the execute command functionality for the containers in this task. If true, this enables execute command functionality on all containers in the task.
No
false
boolean
group
The name of the task group to associate with the task. The default value is the family name of the task definition (for example, family:my_family_name).
No
''
string
launch_type
The launch type on which to run your task. Possible values EC2, FARGATE, or an empty string. For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide.
No
FARGATE
enum
overrides
A list of container overrides in JSON format that specify the name of a container in the specified task definition and the overrides it should receive.
No
''
string
placement_constraints
An array of placement constraint objects to use for the task. You can specify up to 10 constraints per task (including constraints in the task definition and those specified at runtime). Expected format: type=string,field=string.
No
''
string
placement_strategy
The placement strategy objects to use for the task. You can specify a maximum of five strategy rules per task. Expected format: type=string,field=string.
No
''
string
platform_version
Use this to specify the platform version that the task should run on. A platform version should only be specified for tasks using the Fargate launch type.
No
''
string
profile_name
AWS profile name to be configured.
No
default
string
propagate_tags
Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action.
No
false
boolean
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
$AWS_DEFAULT_REGION
string
run_task_output
Specifies a local json file to save the output logs from the aws ecs run_task command. Use tools like JQ to read and parse this information such as "task-arns" and "task-ids"
No
''
string
security_group_ids
List of security group ids separated by commas. Expected Format: sg-010a460f7f442fa75,sg-010a420f7faa5fa75
No
''
string
started_by
An optional tag specified when a task is started. For example, if you automatically trigger a task to run a batch process job, you could apply a unique identifier for that job to your task with the startedBy parameter. You can then identify which tasks belong to that job by filtering the results of a ListTasks call with the startedBy value. Up to 36 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.
No
''
string
subnet_ids
List of subnet ids separated by commas. Expected Format: subnet-70faa93b,subnet-bcc54b93
No
''
string
tags
The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Expected format: key=string,value=string.
No
''
string
task_definition
The family and revision (family:revision) or full ARN of the task definition to run. If a revision is not specified, the latest ACTIVE revision is used.
Yes
-
string

update_service

Registers a task definition for the given ECS service and updates the service to use it. Optionally polls the status of the deployment until the created task definition revision has reached its desired running task count and is the only revision deployed for the service.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cluster
The short name or full ARN of the cluster that hosts the service.
Yes
-
string
codedeploy_application_name
The name of the AWS CodeDeploy application used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_capacity_provider_base
The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and codedeploy_capacity_provider_weight.
No
''
string
codedeploy_capacity_provider_name
The name of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with capacity-provider-base and capacity-provider-weight.
No
''
string
codedeploy_capacity_provider_weight
The weight of AWS Capacity Provider to be added to CodeDeploy deployment. Weight must be greater than 0. Must be used with codedeploy_capacity_provider_name and codedeploy_capacity_provider_base.
No
''
string
codedeploy_deployment_group_name
The name of the AWS CodeDeploy deployment group used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_load_balanced_container_name
The name of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
''
string
codedeploy_load_balanced_container_port
The port of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY".
No
'80'
string
container_docker_label_updates
Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas.
No
''
string
container_env_var_updates
Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas.
No
''
string
container_image_name_updates
Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used.
No
''
string
container_secret_updates
Use this to update or set the values of secret variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas.
No
''
string
deployment_config_name
The name of a CODE DEPLOY deployment configuration associated with the IAM user or AWS account. If not specified, the value configured in the deployment group is used as the default.
No
''
string
deployment_controller
The deployment controller to use for the service. Defaulted to ECS
No
ECS
enum
enable_circuit_breaker
Determines whether a service deployment will fail if the service can't reach a steady state. To use the deployment circuit breaker for CodeDeploy services, the verify_revision_is_deployed parameter must be set to true.
No
false
boolean
fail_on_verification_timeout
Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts. Only in use when verify_revision_is_deployed is set to true.
No
true
boolean
family
Name of the task definition's family.
Yes
-
string
force_new_deployment
Whether to force a new deployment of the service. Not applicable to ECS services that are of the Blue/Green Deployment type.
No
false
boolean
max_poll_attempts
The maximum number of attempts to poll the deployment status before giving up. Only in use when verify_revision_is_deployed is set to true.
No
50
integer
poll_interval
The polling interval, in seconds. Only in use when verify_revision_is_deployed is set to true.
No
20
integer
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use for looking up task definitions.
No
$AWS_DEFAULT_REGION
string
service_name
The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition.
No
''
string
skip_task_definition_registration
Whether to skip registration of a new task definition.
No
false
boolean
task_definition_tags
The metadata that you apply to the task definition to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. (Existing environment variables not included in this parameter will not be removed) Expected formats: - Shorthand Syntax key=string,value=string ... - JSON Syntax [{"key": "string","value": "string"} ... ] Values should not contain commas.
No
''
string
verification_timeout
The maximum amount of time to wait for a blue/green deployment to complete before timing out. Only in use when the deployment controller is the blue/green deployment type.
No
10m
string
verify_revision_is_deployed
Runs the verify_revision_is_deployed Orb command to verify that the revision has been deployed and is the only deployed revision for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached.
No
false
boolean

update_task_definition

Registers a task definition based on the last task definition, except with the Docker image/tag names and environment variables of the containers updated according to this command's parameters.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
container_docker_label_updates
Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas.
No
''
string
container_env_var_updates
Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas.
No
''
string
container_image_name_updates
Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used.
No
''
string
container_secret_updates
Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas.
No
''
string
family
Name of the task definition's family.
Yes
-
string
previous_revision_number
Optional previous task's revision number
No
''
string
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
$AWS_DEFAULT_REGION
string

update_task_definition_from_json

Registers a task definition based on a json file.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
$AWS_DEFAULT_REGION
string
task_definition_json
Location of your .json task definition file (relative or absolute).
Yes
-
string

verify_revision_is_deployed

Polls the service's deployment status at intervals until the given task definition revision is the only one deployed for the service, and for the task definition revision's running task count to match the desired count. Does not support ECS services that are of the Blue/Green Deployment type.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cluster
The short name or full ARN of the cluster that hosts the service.
Yes
-
string
fail_on_verification_timeout
Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts.
No
true
boolean
family
Name of the task definition's family.
Yes
-
string
max_poll_attempts
The maximum number of attempts to poll for the deployment status before giving up.
No
50
integer
poll_interval
The polling interval, in seconds.
No
20
integer
profile_name
AWS profile name to be configured.
No
default
string
region
AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
No
$AWS_DEFAULT_REGION
string
service_name
The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition.
No
''
string
task_definition_arn
ARN of the task definition whose deployment status is to be monitored.
Yes
-
string

Executors

default

A Python Docker image built to run on CircleCI that contains python installed with pyenv and packaging tools pip, pipenv, and poetry.

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
resource_class
Configure the executor resource class
No
medium
enum
tag
Select any of the available tags here: https://circleci.com/developer/images/image/cimg/python.
No
3.10.4
string

Orb Source

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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | Manage and deploy apps via Amazon's AWS Elastic Container Service (ECS) on CircleCI. Supports the EC2 and Fargate launch types and Blue/Green deployment via CodeDeploy. display: home_url: https://aws.amazon.com/ecs/ source_url: https://github.com/CircleCI-Public/aws-ecs-orb commands: deploy_ecs_scheduled_task: description: | Deploy an ECS Scheduled Task Rule after updating a task definition. The update_task_definition command must be run first. parameters: region: default: $AWS_DEFAULT_REGION description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string rule_name: description: The name of the scheduled task's rule to update. type: string steps: - run: command: | #!/bin/bash td_arn=$CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "$td_arn" ]; then echo "Updated task definition not found. Please run update-task-definition command before deploy-ecs-scheduled-task" exit 1 fi ORB_STR_RULE_NAME="$(circleci env subst "${ORB_STR_RULE_NAME}")" if [ -z "$ORB_STR_RULE_NAME" ]; then echo "To deploy with an scheduled task, you must provide a rule name" exit 1 fi CLI_OUTPUT_FILE=$(mktemp cli-output.json.XXXX) CLI_INPUT_FILE=$(mktemp cli-input.json.XXXX) aws events list-targets-by-rule --rule "$ORB_STR_RULE_NAME" --output json --region "$ORB_AWS_REGION" > "$CLI_OUTPUT_FILE" if < "$CLI_OUTPUT_FILE" jq ' .Targets[] | has("EcsParameters")' | grep "false"; then echo "Invalid ECS Rule. $ORB_STR_RULE_NAME does not contain EcsParameters key. Please create a valid ECS Rule and try again" exit 1 fi < "$CLI_OUTPUT_FILE" jq --arg td_arn "$td_arn" '.Targets[].EcsParameters.TaskDefinitionArn |= $td_arn' > "$CLI_INPUT_FILE" aws events put-targets --rule "$ORB_STR_RULE_NAME" --cli-input-json "$(cat "$CLI_INPUT_FILE")" --region "$ORB_AWS_REGION" environment: ORB_AWS_REGION: << parameters.region >> ORB_STR_RULE_NAME: <<parameters.rule_name>> name: Deploy rule with updated task definition install_ecs_cli: description: Installs the AWS ECS CLI parameters: install_dir: default: /usr/local/bin/ecs-cli description: Specify the installation directory for the AWS ECS CLI. By default, the installation directory will be /usr/local/bin/ecs-cli. type: string override_installed: default: false description: | By default, if the AWS ECS CLI is detected on the system, the install will be skipped. Enable this to override the installed version and install your specified version. type: boolean version: default: latest description: Specify the version of the AWS ECS CLI to install. By default, the latest version will be installed. type: string steps: - run: command: |+ #!/bin/bash if [ $EUID == 0 ]; then export SUDO=""; else export SUDO="sudo"; fi ORB_STR_VERSION="$(circleci env subst "${ORB_STR_VERSION}")" ORB_EVAL_INSTALL_DIR="$(eval echo "${ORB_EVAL_INSTALL_DIR}")" # Platform check if uname -a | grep "Darwin"; then export SYS_ENV_PLATFORM="darwin" MACOS_VERSION=$(sw_vers -productVersion | cut -d. -f1) DELIMIT_VERSION=$(echo "$ORB_STR_VERSION" | cut -dv -f2) MAJOR=$(echo "$DELIMIT_VERSION" | cut -d. -f1) MINOR=$(echo "$DELIMIT_VERSION" | cut -d. -f2) if [ "$MACOS_VERSION" -ge "12" ] && [ "$MAJOR" -le "1" ] && [ "$MINOR" -lt "9" ]; then echo "Error: ECS CLI version ${ORB_STR_VERSION} is not supported with macOS version ${MACOS_VERSION}. Please upgrade to macOS version 1.9 or later." exit 1 fi elif uname -a | grep "x86_64 GNU/Linux"; then export SYS_ENV_PLATFORM="linux" else echo "This platform appears to be unsupported." uname -a exit 1 fi Install_ECS_CLI(){ if [ "$SYS_ENV_PLATFORM" != "darwin" ]; then $SUDO curl -Lo "${ORB_EVAL_INSTALL_DIR}" "https://amazon-ecs-cli.s3.amazonaws.com/ecs-cli-${SYS_ENV_PLATFORM}-amd64-$1" $SUDO chmod +x "${ORB_EVAL_INSTALL_DIR}" else brew install amazon-ecs-cli fi } Uninstall_ECS_CLI(){ echo "Uninstalling ECS CLI..." ECS_CLI_PATH="$(command -v ecs-cli)" $SUDO rm -rf "${ECS_CLI_PATH}" } if ! command -v ecs-cli; then echo "Installing ECS CLI..." Install_ECS_CLI "${ORB_STR_VERSION}" ecs-cli --version else if [ "$ORB_BOOL_OVERRIDE_INSTALLED" = 1 ]; then echo "Overriding installed ECS CLI..." Uninstall_ECS_CLI Install_ECS_CLI "${ORB_STR_VERSION}" ecs-cli --version else echo "ECS CLI is already installed." ecs-cli --version fi fi environment: ORB_BOOL_OVERRIDE_INSTALLED: <<parameters.override_installed>> ORB_EVAL_INSTALL_DIR: <<parameters.install_dir>> ORB_STR_VERSION: <<parameters.version>> name: Install AWS ECS CLI run_task: description: | Starts a new ECS task using the specified task definition and other parameters. For more information on ECS Run-Task options, see: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/run_task.html parameters: assign_public_ip: default: DISABLED description: | Assign a public IP or not enum: - ENABLED - DISABLED type: enum awsvpc: default: true description: | Does your task defintion use awsvpc mode or not. If so, this should be true and you should also include subnet_ids and optionally security_group_ids / assign_public_ips. type: boolean capacity_provider_strategy: default: "" description: | The capacity provider strategy to use for the task. If a `capacity_provider_strategy` is specified, the `launch_type` parameter must be set to an empty string. type: string cluster: description: The name or ARN of the cluster on which to run the task. type: string count: default: 1 description: | "The number of instantiations of the specified task to place on your cluster. You can specify up to 10 tasks per call." type: integer enable_ecs_managed_tags: default: false description: | "Specifies whether to enable Amazon ECS managed tags for the task." type: boolean enable_execute_command: default: false description: | Determines whether to use the execute command functionality for the containers in this task. If true, this enables execute command functionality on all containers in the task. type: boolean group: default: "" description: | The name of the task group to associate with the task. The default value is the family name of the task definition (for example, family:my_family_name). type: string launch_type: default: FARGATE description: | The launch type on which to run your task. Possible values EC2, FARGATE, or an empty string. For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide. enum: - FARGATE - EC2 - "" type: enum overrides: default: "" description: | A list of container overrides in JSON format that specify the name of a container in the specified task definition and the overrides it should receive. type: string placement_constraints: default: "" description: | An array of placement constraint objects to use for the task. You can specify up to 10 constraints per task (including constraints in the task definition and those specified at runtime). Expected format: type=string,field=string. type: string placement_strategy: default: "" description: | The placement strategy objects to use for the task. You can specify a maximum of five strategy rules per task. Expected format: type=string,field=string. type: string platform_version: default: "" description: | Use this to specify the platform version that the task should run on. A platform version should only be specified for tasks using the Fargate launch type. type: string profile_name: default: default description: AWS profile name to be configured. type: string propagate_tags: default: false description: | Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action. type: boolean region: default: $AWS_DEFAULT_REGION description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string run_task_output: default: "" description: | Specifies a local json file to save the output logs from the aws ecs run_task command. Use tools like JQ to read and parse this information such as "task-arns" and "task-ids" type: string security_group_ids: default: "" description: | List of security group ids separated by commas. Expected Format: sg-010a460f7f442fa75,sg-010a420f7faa5fa75 type: string started_by: default: "" description: | An optional tag specified when a task is started. For example, if you automatically trigger a task to run a batch process job, you could apply a unique identifier for that job to your task with the startedBy parameter. You can then identify which tasks belong to that job by filtering the results of a ListTasks call with the startedBy value. Up to 36 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. type: string subnet_ids: default: "" description: | List of subnet ids separated by commas. Expected Format: subnet-70faa93b,subnet-bcc54b93 type: string tags: default: "" description: | The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Expected format: key=string,value=string. type: string task_definition: description: | The family and revision (family:revision) or full ARN of the task definition to run. If a revision is not specified, the latest ACTIVE revision is used. type: string steps: - run: command: "#!/bin/bash\nif [[ $EUID == 0 ]]; then export SUDO=\"\"; else export SUDO=\"sudo\"; fi\n# These variables are evaluated so the config file may contain and pass in environment variables to the parameters.\nORB_STR_CLUSTER_NAME=\"$(circleci env subst \"$ORB_STR_CLUSTER_NAME\")\"\nORB_STR_TASK_DEF=\"$(circleci env subst \"$ORB_STR_TASK_DEF\")\"\nORB_STR_STARTED_BY=\"$(circleci env subst \"$ORB_STR_STARTED_BY\")\"\nORB_STR_GROUP=\"$(circleci env subst \"$ORB_STR_GROUP\")\"\nORB_STR_PLACEMENT_STRATEGY=\"$(circleci env subst \"$ORB_STR_PLACEMENT_STRATEGY\")\"\nORB_STR_PLACEMENT_CONSTRAINTS=\"$(circleci env subst \"$ORB_STR_PLACEMENT_CONSTRAINTS\")\"\nORB_STR_PLATFORM_VERSION=\"$(circleci env subst \"$ORB_STR_PLATFORM_VERSION\")\"\nORB_STR_TAGS=\"$(circleci env subst \"$ORB_STR_TAGS\")\"\nORB_STR_CD_CAPACITY_PROVIDER_STRATEGY=\"$(circleci env subst \"$ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY\")\"\nORB_STR_RUN_TASK_OUTPUT=\"$(circleci env subst \"$ORB_STR_RUN_TASK_OUTPUT\")\"\nORB_STR_PROFILE_NAME=\"$(circleci env subst \"$ORB_STR_PROFILE_NAME\")\"\nORB_STR_ASSIGN_PUB_IP=\"$(circleci env subst \"$ORB_STR_ASSIGN_PUB_IP\")\"\nORB_AWS_REGION=\"$(circleci env subst \"$ORB_AWS_REGION\")\"\n\nif [[ \"$ORB_STR_OVERRIDES\" == *\"\\${\"* ]]; then\n ORB_STR_OVERRIDES=\"$(echo \"${ORB_STR_OVERRIDES}\" | circleci env subst)\"\nfi\n\nset -o noglob\nif [ -n \"$ORB_STR_PLATFORM_VERSION\" ]; then\n echo \"Setting --platform-version\"\n set -- \"$@\" --platform-version \"$ORB_STR_PLATFORM_VERSION\"\nfi\nif [ -n \"$ORB_STR_STARTED_BY\" ]; then\n echo \"Setting --started-by\"\n set -- \"$@\" --started-by \"$ORB_STR_STARTED_BY\"\nfi\nif [ -n \"$ORB_STR_GROUP\" ]; then\n echo \"Setting --group\"\n set -- \"$@\" --group \"$ORB_STR_GROUP\"\nfi\nif [ -n \"$ORB_STR_OVERRIDES\" ]; then\n echo \"Setting --overrides\"\n set -- \"$@\" --overrides \"$ORB_STR_OVERRIDES\"\nfi\nif [ -n \"$ORB_STR_TAGS\" ]; then\n echo \"Setting --tags\"\n set -- \"$@\" --tags \"$ORB_STR_TAGS\"\nfi\nif [ -n \"$ORB_STR_PLACEMENT_CONSTRAINTS\" ]; then\n echo \"Setting --placement-constraints\"\n set -- \"$@\" --placement-constraints \"$ORB_STR_PLACEMENT_CONSTRAINTS\"\nfi\nif [ -n \"$ORB_STR_PLACEMENT_STRATEGY\" ]; then\n echo \"Setting --placement-strategy\"\n set -- \"$@\" --placement-strategy \"$ORB_STR_PLACEMENT_STRATEGY\"\nfi\nif [ \"$ORB_BOOL_ENABLE_ECS_MANAGED_TAGS\" == \"1\" ]; then\n echo \"Setting --enable-ecs-managed-tags\"\n set -- \"$@\" --enable-ecs-managed-tags\nfi\nif [ \"$ORB_BOOL_ENABLE_EXECUTE_COMMAND\" == \"1\" ]; then\n echo \"Setting --enable-execute-command\"\n set -- \"$@\" --enable-execute-command\nfi\nif [ \"$ORB_BOOL_PROPAGATE_TAGS\" == \"1\" ]; then\n echo \"Setting --propagate-tags\"\n set -- \"$@\" --propagate-tags \"TASK_DEFINITION\"\nfi\nif [ \"$ORB_BOOL_AWSVPC\" == \"1\" ]; then\n echo \"Setting --network-configuration\"\n if [ -z \"$ORB_STR_SUBNET_ID\" ]; then\n echo '\"subnet-ids\" is missing.'\n echo 'When \"awsvpc\" is enabled, \"subnet-ids\" must be provided.'\n exit 1\n fi\n ORB_STR_SUBNET_ID=\"$(circleci env subst \"$ORB_STR_SUBNET_ID\")\"\n ORB_STR_SEC_GROUP_ID=\"$(circleci env subst \"$ORB_STR_SEC_GROUP_ID\")\"\n set -- \"$@\" --network-configuration awsvpcConfiguration=\"{subnets=[$ORB_STR_SUBNET_ID],securityGroups=[$ORB_STR_SEC_GROUP_ID],assignPublicIp=$ORB_STR_ASSIGN_PUB_IP}\"\nfi\nif [ -n \"$ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY\" ]; then\n echo \"Setting --capacity-provider-strategy\"\n # do not quote\n # shellcheck disable=SC2086\n set -- \"$@\" --capacity-provider-strategy $ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY\nfi\n\nif [ -n \"$ORB_VAL_LAUNCH_TYPE\" ]; then\n if [ -n \"$ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY\" ]; then\n echo \"Error: \"\n echo 'If a \"capacity-provider-strategy\" is specified, the \"launch-type\" parameter must be set to an empty string.'\n exit 1\n else\n echo \"Setting --launch-type\"\n set -- \"$@\" --launch-type \"$ORB_VAL_LAUNCH_TYPE\"\n fi\nfi\n\n\necho \"Setting --count\"\nset -- \"$@\" --count \"$ORB_INT_COUNT\"\necho \"Setting --task-definition\"\nset -- \"$@\" --task-definition \"$ORB_STR_TASK_DEF\"\necho \"Setting --cluster\"\nset -- \"$@\" --cluster \"$ORB_STR_CLUSTER_NAME\"\n\n\nif [ -n \"${ORB_STR_RUN_TASK_OUTPUT}\" ]; then\n set -x\n aws ecs run-task --profile \"${ORB_STR_PROFILE_NAME}\" --region \"${ORB_AWS_REGION}\" \"$@\" | tee \"${ORB_STR_RUN_TASK_OUTPUT}\"\n set +x\nelse\n set -x \n aws ecs run-task --profile \"${ORB_STR_PROFILE_NAME}\" --region \"${ORB_AWS_REGION}\" \"$@\"\n set +x\nfi\n" environment: ORB_AWS_REGION: << parameters.region >> ORB_BOOL_AWSVPC: <<parameters.awsvpc>> ORB_BOOL_ENABLE_ECS_MANAGED_TAGS: <<parameters.enable_ecs_managed_tags>> ORB_BOOL_ENABLE_EXECUTE_COMMAND: <<parameters.enable_execute_command>> ORB_BOOL_PROPAGATE_TAGS: <<parameters.propagate_tags>> ORB_INT_COUNT: <<parameters.count>> ORB_STR_ASSIGN_PUB_IP: <<parameters.assign_public_ip>> ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY: <<parameters.capacity_provider_strategy>> ORB_STR_CLUSTER_NAME: <<parameters.cluster>> ORB_STR_GROUP: <<parameters.group>> ORB_STR_OVERRIDES: <<parameters.overrides>> ORB_STR_PLACEMENT_CONSTRAINTS: <<parameters.placement_constraints>> ORB_STR_PLACEMENT_STRATEGY: <<parameters.placement_strategy>> ORB_STR_PLATFORM_VERSION: <<parameters.platform_version>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> ORB_STR_RUN_TASK_OUTPUT: <<parameters.run_task_output>> ORB_STR_SEC_GROUP_ID: <<parameters.security_group_ids>> ORB_STR_STARTED_BY: <<parameters.started_by>> ORB_STR_SUBNET_ID: <<parameters.subnet_ids>> ORB_STR_TAGS: <<parameters.tags>> ORB_STR_TASK_DEF: <<parameters.task_definition>> ORB_VAL_LAUNCH_TYPE: <<parameters.launch_type>> name: Run Task update_service: description: | Registers a task definition for the given ECS service and updates the service to use it. Optionally polls the status of the deployment until the created task definition revision has reached its desired running task count and is the only revision deployed for the service. parameters: cluster: description: The short name or full ARN of the cluster that hosts the service. type: string codedeploy_application_name: default: "" description: | The name of the AWS CodeDeploy application used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_capacity_provider_base: default: "" description: | The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and codedeploy_capacity_provider_weight. type: string codedeploy_capacity_provider_name: default: "" description: | The name of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with capacity-provider-base and capacity-provider-weight. type: string codedeploy_capacity_provider_weight: default: "" description: | The weight of AWS Capacity Provider to be added to CodeDeploy deployment. Weight must be greater than 0. Must be used with codedeploy_capacity_provider_name and codedeploy_capacity_provider_base. type: string codedeploy_deployment_group_name: default: "" description: | The name of the AWS CodeDeploy deployment group used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_load_balanced_container_name: default: "" description: | The name of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_load_balanced_container_port: default: "80" description: | The port of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string container_docker_label_updates: default: "" description: | Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas. type: string container_env_var_updates: default: "" description: | Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas. type: string container_image_name_updates: default: "" description: | Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used. type: string container_secret_updates: default: "" description: | Use this to update or set the values of secret variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas. type: string deployment_config_name: default: "" description: | The name of a CODE DEPLOY deployment configuration associated with the IAM user or AWS account. If not specified, the value configured in the deployment group is used as the default. type: string deployment_controller: default: ECS description: The deployment controller to use for the service. Defaulted to ECS enum: - ECS - CODE_DEPLOY type: enum enable_circuit_breaker: default: false description: | Determines whether a service deployment will fail if the service can't reach a steady state. To use the deployment circuit breaker for CodeDeploy services, the verify_revision_is_deployed parameter must be set to true. type: boolean fail_on_verification_timeout: default: true description: | Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts. Only in use when verify_revision_is_deployed is set to true. type: boolean family: description: Name of the task definition's family. type: string force_new_deployment: default: false description: | Whether to force a new deployment of the service. Not applicable to ECS services that are of the Blue/Green Deployment type. type: boolean max_poll_attempts: default: 50 description: | The maximum number of attempts to poll the deployment status before giving up. Only in use when verify_revision_is_deployed is set to true. type: integer poll_interval: default: 20 description: | The polling interval, in seconds. Only in use when verify_revision_is_deployed is set to true. type: integer profile_name: default: default description: AWS profile name to be configured. type: string region: default: $AWS_DEFAULT_REGION description: AWS region to use for looking up task definitions. type: string service_name: default: "" description: The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition. type: string skip_task_definition_registration: default: false description: | Whether to skip registration of a new task definition. type: boolean task_definition_tags: default: "" description: | The metadata that you apply to the task definition to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. (Existing environment variables not included in this parameter will not be removed) Expected formats: - Shorthand Syntax key=string,value=string ... - JSON Syntax [{"key": "string","value": "string"} ... ] Values should not contain commas. type: string verification_timeout: default: 10m description: | The maximum amount of time to wait for a blue/green deployment to complete before timing out. Only in use when the deployment controller is the blue/green deployment type. type: string verify_revision_is_deployed: default: false description: | Runs the verify_revision_is_deployed Orb command to verify that the revision has been deployed and is the only deployed revision for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached. type: boolean steps: - unless: condition: << parameters.skip_task_definition_registration >> steps: - update_task_definition: container_docker_label_updates: << parameters.container_docker_label_updates >> container_env_var_updates: << parameters.container_env_var_updates >> container_image_name_updates: << parameters.container_image_name_updates >> container_secret_updates: << parameters.container_secret_updates >> family: << parameters.family >> profile_name: << parameters.profile_name >> region: << parameters.region >> - when: condition: << parameters.skip_task_definition_registration >> steps: - run: command: | TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ --task-definition << parameters.family >> \ --output text \ --query 'taskDefinition.taskDefinitionArn' \ --profile << parameters.profile_name >> \ --region << parameters.region >>) echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV name: Retrieve previous task definition - when: condition: << parameters.task_definition_tags >> steps: - run: command: | aws ecs tag-resource \ --resource-arn ${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN} \ --tags <<parameters.task_definition_tags>> \ --profile=<< parameters.profile_name >> \ --region << parameters.region >> name: Update task definition with additional tags - when: condition: equal: - CODE_DEPLOY - << parameters.deployment_controller >> steps: - run: command: "#!/bin/bash\nset -o noglob\n\n# These variables are evaluated so the config file may contain and pass in environment variables to the parameters.\nORB_STR_CD_APP_NAME=\"$(circleci env subst \"$ORB_STR_CD_APP_NAME\")\"\nORB_STR_CD_DEPLOY_GROUP_NAME=\"$(circleci env subst \"$ORB_STR_CD_DEPLOY_GROUP_NAME\")\"\nORB_STR_CD_LOAD_BALANCED_CONTAINER_NAME=\"$(circleci env subst \"$ORB_STR_CD_LOAD_BALANCED_CONTAINER_NAME\")\"\nORB_STR_CD_CAPACITY_PROVIDER_WEIGHT=\"$(circleci env subst \"$ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT\")\"\nORB_STR_CD_CAPACITY_PROVIDER_BASE=\"$(circleci env subst \"$ORB_STR_CD_CAPACITY_PROVIDER_BASE\")\"\nORB_STR_CD_DEPLOYMENT_CONFIG_NAME=\"$(circleci env subst \"$ORB_STR_CD_DEPLOYMENT_CONFIG_NAME\")\"\nORB_STR_PROFILE_NAME=\"$(circleci env subst \"$ORB_STR_PROFILE_NAME\")\"\nORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT=\"$(circleci env subst \"$ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT\")\"\nORB_AWS_REGION=\"$(circleci env subst \"$ORB_AWS_REGION\")\"\n\nDEPLOYED_REVISION=\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\"\n\nif [ \"$ORB_BOOL_ENABLE_CIRCUIT_BREAKER\" == \"1\" ] && [ \"$ORB_BOOL_VERIFY_REV_DEPLOY\" == \"0\" ]; then\n echo \"enable-circuit-breaker is set to true, but verify-revision-deploy is set to false. verfiy-revision-deploy must be set to true to use enable-circuit-breaker.\"\n exit 1\nfi\n\nif [ -n \"$ORB_STR_CD_CAPACITY_PROVIDER_NAME\" ]; then \n if [ -z \"$ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT\" ] || [ -z \"$ORB_STR_CD_CAPACITY_PROVIDER_BASE\" ]; then \n echo \"Capacity Provider base and weight parameter must all be provided. Please try again\"\n exit 1\n else \n REVISION=\"{\\\"revisionType\\\": \\\"AppSpecContent\\\", \\\"appSpecContent\\\": {\\\"content\\\": \\\"{\\\\\\\"version\\\\\\\": 1, \\\\\\\"Resources\\\\\\\": [{\\\\\\\"TargetService\\\\\\\": {\\\\\\\"Type\\\\\\\": \\\\\\\"AWS::ECS::Service\\\\\\\", \\\\\\\"Properties\\\\\\\": {\\\\\\\"TaskDefinition\\\\\\\": \\\\\\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\\\\\", \\\\\\\"LoadBalancerInfo\\\\\\\": {\\\\\\\"ContainerName\\\\\\\": \\\\\\\"$ORB_STR_CD_LOAD_BALANCED_CONTAINER_NAME\\\\\\\", \\\\\\\"ContainerPort\\\\\\\": $ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT},\\\\\\\"CapacityProviderStrategy\\\\\\\":[{\\\\\\\"CapacityProvider\\\\\\\":\\\\\\\"$ORB_STR_CD_CAPACITY_PROVIDER_NAME\\\\\\\", \\\\\\\"Base\\\\\\\":${ORB_STR_CD_CAPACITY_PROVIDER_BASE}, \\\\\\\"Weight\\\\\\\":${ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT}}]}}}]}\\\"}}\"\n fi\nelse\n REVISION=\"{\\\"revisionType\\\": \\\"AppSpecContent\\\", \\\"appSpecContent\\\": {\\\"content\\\": \\\"{\\\\\\\"version\\\\\\\": 1, \\\\\\\"Resources\\\\\\\": [{\\\\\\\"TargetService\\\\\\\": {\\\\\\\"Type\\\\\\\": \\\\\\\"AWS::ECS::Service\\\\\\\", \\\\\\\"Properties\\\\\\\": {\\\\\\\"TaskDefinition\\\\\\\": \\\\\\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\\\\\", \\\\\\\"LoadBalancerInfo\\\\\\\": {\\\\\\\"ContainerName\\\\\\\": \\\\\\\"$ORB_STR_CD_LOAD_BALANCED_CONTAINER_NAME\\\\\\\", \\\\\\\"ContainerPort\\\\\\\": $ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT}}}}]}\\\"}}\"\nfi \n\nif [ -n \"$ORB_STR_CD_DEPLOYMENT_CONFIG_NAME\" ]; then\n set -- \"$@\" --deployment-config-name \"${ORB_STR_CD_DEPLOYMENT_CONFIG_NAME}\"\nfi\n\nDEPLOYMENT_ID=$(aws deploy create-deployment \\\n --application-name \"$ORB_STR_CD_APP_NAME\" \\\n --deployment-group-name \"$ORB_STR_CD_DEPLOY_GROUP_NAME\" \\\n --profile \"$ORB_STR_PROFILE_NAME\" \\\n --query deploymentId \\\n --revision \"${REVISION}\" \\\n --region \"${ORB_AWS_REGION}\" \\\n \"$@\" \\\n --output text)\n\necho \"Created CodeDeploy deployment: $DEPLOYMENT_ID\"\n\nif [ \"$ORB_BOOL_VERIFY_REV_DEPLOY\" == \"1\" ]; then\n echo \"Waiting for deployment to succeed.\"\n if aws deploy wait deployment-successful --deployment-id \"${DEPLOYMENT_ID}\" --profile \"${ORB_STR_PROFILE_NAME}\" --region \"${ORB_AWS_REGION}\"; then\n echo \"Deployment succeeded.\"\n elif [ \"$ORB_BOOL_ENABLE_CIRCUIT_BREAKER\" == \"1\" ]; then\n echo \"Deployment failed. Rolling back.\"\n aws deploy stop-deployment --deployment-id \"${DEPLOYMENT_ID}\" --auto-rollback-enabled --profile \"${ORB_STR_PROFILE_NAME}\" --region \"${ORB_AWS_REGION}\"\n else\n echo \"Deployment failed. Exiting.\"\n exit 1\n fi\nfi\n\necho \"export CCI_ORB_AWS_ECS_DEPLOYMENT_ID='${DEPLOYMENT_ID}'\" >> \"$BASH_ENV\"\necho \"export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'\" >> \"$BASH_ENV\"\n" environment: DEPLOYMENT_CONTROLLER: <<parameters.deployment_controller>> ORB_AWS_REGION: << parameters.region >> ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>> ORB_BOOL_VERIFY_REV_DEPLOY: <<parameters.verify_revision_is_deployed>> ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT: <<parameters.codedeploy_load_balanced_container_port>> ORB_STR_CD_APP_NAME: <<parameters.codedeploy_application_name>> ORB_STR_CD_CAPACITY_PROVIDER_BASE: <<parameters.codedeploy_capacity_provider_base>> ORB_STR_CD_CAPACITY_PROVIDER_NAME: <<parameters.codedeploy_capacity_provider_name>> ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT: <<parameters.codedeploy_capacity_provider_weight>> ORB_STR_CD_DEPLOY_GROUP_NAME: <<parameters.codedeploy_deployment_group_name>> ORB_STR_CD_DEPLOYMENT_CONFIG_NAME: <<parameters.deployment_config_name>> ORB_STR_CD_LOAD_BALANCED_CONTAINER_NAME: <<parameters.codedeploy_load_balanced_container_name>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> name: Update ECS Blue/Green service with registered task definition. no_output_timeout: << parameters.verification_timeout >> - when: condition: equal: - ECS - << parameters.deployment_controller >> steps: - run: command: | #!/bin/bash set -o noglob # These variables are evaluated so the config file may contain and pass in environment variables to the parameters. ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_CLUSTER_NAME="$(circleci env subst "$ORB_STR_CLUSTER_NAME")" ORB_STR_SERVICE_NAME="$(circleci env subst "$ORB_STR_SERVICE_NAME")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "${ORB_STR_SERVICE_NAME}" ]; then ORB_STR_SERVICE_NAME="$ORB_STR_FAMILY" fi if [ "$ORB_BOOL_FORCE_NEW_DEPLOY" == "1" ]; then set -- "$@" --force-new-deployment fi if [ "$ORB_BOOL_ENABLE_CIRCUIT_BREAKER" == "1" ]; then set -- "$@" --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true}" fi DEPLOYED_REVISION=$(aws ecs update-service \ --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --service "${ORB_STR_SERVICE_NAME}" \ --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ --output text \ --region "${ORB_AWS_REGION}" \ --query service.taskDefinition \ "$@") echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> "$BASH_ENV" environment: ORB_AWS_REGION: << parameters.region >> ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>> ORB_BOOL_FORCE_NEW_DEPLOY: <<parameters.force_new_deployment>> ORB_STR_CLUSTER_NAME: <<parameters.cluster>> ORB_STR_FAMILY: <<parameters.family>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> ORB_STR_SERVICE_NAME: <<parameters.service_name>> name: Update service with registered task definition - when: condition: and: - << parameters.verify_revision_is_deployed >> - equal: - ECS - << parameters.deployment_controller >> steps: - verify_revision_is_deployed: cluster: << parameters.cluster >> fail_on_verification_timeout: << parameters.fail_on_verification_timeout >> family: << parameters.family >> max_poll_attempts: << parameters.max_poll_attempts >> poll_interval: << parameters.poll_interval >> profile_name: << parameters.profile_name >> region: << parameters.region >> service_name: << parameters.service_name >> task_definition_arn: $CCI_ORB_AWS_ECS_DEPLOYED_REVISION update_task_definition: description: Registers a task definition based on the last task definition, except with the Docker image/tag names and environment variables of the containers updated according to this command's parameters. parameters: container_docker_label_updates: default: "" description: | Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas. type: string container_env_var_updates: default: "" description: | Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas. type: string container_image_name_updates: default: "" description: | Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used. type: string container_secret_updates: default: "" description: | Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas. type: string family: description: Name of the task definition's family. type: string previous_revision_number: default: "" description: Optional previous task's revision number type: string profile_name: default: default description: AWS profile name to be configured. type: string region: default: $AWS_DEFAULT_REGION description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string steps: - run: command: | #!/bin/bash set -o noglob # These variables are evaluated so the config file may contain and pass in environment variables to the parameters. ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_CONTAINER_IMAGE_NAME_UPDATES="$(circleci env subst "$ORB_STR_CONTAINER_IMAGE_NAME_UPDATES")" ORB_STR_CONTAINER_ENV_VAR_UPDATE="$(circleci env subst "$ORB_STR_CONTAINER_ENV_VAR_UPDATE")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_STR_CONTAINER_SECRET_UPDATES="$(circleci env subst "$ORB_STR_CONTAINER_SECRET_UPDATES")" ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES="$(circleci env subst "$ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES")" ORB_STR_PREVIOUS_REVISION_NUMBER="$(circleci env subst "$ORB_STR_PREVIOUS_REVISION_NUMBER")" ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "${ECS_PARAM_PREVIOUS_REVISION}" ]; then ECS_TASK_DEFINITION_NAME="$ORB_STR_FAMILY" else ECS_TASK_DEFINITION_NAME="$ORB_STR_FAMILY:$ORB_STR_PREVIOUS_REVISION_NUMBER" fi # shellcheck disable=SC2034 PREVIOUS_TASK_DEFINITION="$(aws ecs describe-task-definition --task-definition "${ECS_TASK_DEFINITION_NAME}" --include TAGS --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}" "$@")" # Prepare script for updating container definitions UPDATE_CONTAINER_DEFS_SCRIPT_FILE=$(mktemp _update_container_defs.py.XXXXXX) chmod +x "$UPDATE_CONTAINER_DEFS_SCRIPT_FILE" cat \<<< "$ORB_SCRIPT_UPDATE_CONTAINER_DEFS" > "$UPDATE_CONTAINER_DEFS_SCRIPT_FILE" # Prepare container definitions CONTAINER_DEFS="$(python "$UPDATE_CONTAINER_DEFS_SCRIPT_FILE" "$PREVIOUS_TASK_DEFINITION" "$ORB_STR_CONTAINER_IMAGE_NAME_UPDATES" "$ORB_STR_CONTAINER_ENV_VAR_UPDATE" "$ORB_STR_CONTAINER_SECRET_UPDATES" "$ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES")" # Escape single quotes from environment variables for BASH_ENV CLEANED_CONTAINER_DEFS=$(echo "$CONTAINER_DEFS" | sed -E "s:':'\\\'':g") # Prepare script for getting task definition values GET_TASK_DFN_VAL_SCRIPT_FILE=$(mktemp _get_task_def_value.py.XXXXXX) chmod +x "$GET_TASK_DFN_VAL_SCRIPT_FILE" cat \<<< "$ORB_SCRIPT_GET_TASK_DFN_VAL" > "$GET_TASK_DFN_VAL_SCRIPT_FILE" # Get other task definition values TASK_ROLE=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'taskRoleArn' "$PREVIOUS_TASK_DEFINITION") EXECUTION_ROLE=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'executionRoleArn' "$PREVIOUS_TASK_DEFINITION") NETWORK_MODE=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'networkMode' "$PREVIOUS_TASK_DEFINITION") VOLUMES=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'volumes' "$PREVIOUS_TASK_DEFINITION") PLACEMENT_CONSTRAINTS=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'placementConstraints' "$PREVIOUS_TASK_DEFINITION") REQ_COMP=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'requiresCompatibilities' "$PREVIOUS_TASK_DEFINITION") TASK_CPU=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'cpu' "$PREVIOUS_TASK_DEFINITION") TASK_MEMORY=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'memory' "$PREVIOUS_TASK_DEFINITION") PID_MODE=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'pidMode' "$PREVIOUS_TASK_DEFINITION") IPC_MODE=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'ipcMode' "$PREVIOUS_TASK_DEFINITION") TAGS=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'tags' "$PREVIOUS_TASK_DEFINITION") PROXY_CONFIGURATION=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'proxyConfiguration' "$PREVIOUS_TASK_DEFINITION") RUNTIME_PLATFORM=$(python "$GET_TASK_DFN_VAL_SCRIPT_FILE" 'runtimePlatform' "$PREVIOUS_TASK_DEFINITION") EPHEMERAL_STORAGE=$(echo "${PREVIOUS_TASK_DEFINITION}" | jq ".taskDefinition.ephemeralStorage //empty" -c) # Make task definition values available as env variables # shellcheck disable=SC2129 echo "export CCI_ORB_AWS_ECS_TASK_ROLE='${TASK_ROLE}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_EXECUTION_ROLE='${EXECUTION_ROLE}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_NETWORK_MODE='${NETWORK_MODE}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_CONTAINER_DEFS='${CLEANED_CONTAINER_DEFS}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_VOLUMES='${VOLUMES}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_PLACEMENT_CONSTRAINTS='${PLACEMENT_CONSTRAINTS}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_REQ_COMP='${REQ_COMP}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_TASK_CPU='${TASK_CPU}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_TASK_MEMORY='${TASK_MEMORY}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_PID_MODE='${PID_MODE}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_IPC_MODE='${IPC_MODE}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_TAGS='${TAGS}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_PROXY_CONFIGURATION='${PROXY_CONFIGURATION}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_RUNTIME_PLATFORM='${RUNTIME_PLATFORM}'" >> "$BASH_ENV" echo "export CCI_ORB_AWS_ECS_EPHEMERAL_STORAGE='${EPHEMERAL_STORAGE}'" >> "$BASH_ENV" rm "$UPDATE_CONTAINER_DEFS_SCRIPT_FILE" "$GET_TASK_DFN_VAL_SCRIPT_FILE" environment: ORB_AWS_REGION: << parameters.region >> ORB_SCRIPT_GET_TASK_DFN_VAL: | from __future__ import absolute_import import sys import json def run(element_name, task_definition_str): try: definition = json.loads(task_definition_str) task_definition = definition['taskDefinition'] except: raise Exception('No valid task definition found: ' + task_definition_str) str_list_types = ['requiresCompatibilities'] json_arr_types = ['placementConstraints', 'volumes', 'tags'] json_obj_types = ['proxyConfiguration', 'runtimePlatform'] if element_name in json_arr_types: output_value = '[]' elif element_name in json_obj_types: output_value = '{}' else: output_value = '' if element_name == 'tags': if element_name in definition: element_value = definition[element_name] output_value = json.dumps(element_value) elif element_name in task_definition: element_value = task_definition[element_name] if element_name in str_list_types: output_value = ' '.join(list_item.strip() for list_item in element_value) elif element_name in json_arr_types or element_name in json_obj_types: output_value = json.dumps(element_value) else: output_value = str(element_value) return output_value if __name__ == '__main__': try: print(run(sys.argv[1], sys.argv[2])) except Exception as e: sys.stderr.write(str(e) + "\n") exit(1) ORB_SCRIPT_UPDATE_CONTAINER_DEFS: "from __future__ import absolute_import\nimport sys\nimport json\n\n# shellcheck disable=SC1036 # Hold-over from previous iteration.\ndef run(previous_task_definition, container_image_name_updates,\n container_env_var_updates, container_secret_updates, container_docker_label_updates):\n try:\n definition = json.loads(previous_task_definition)\n container_definitions = definition['taskDefinition']['containerDefinitions']\n except:\n raise Exception('No valid task definition found: ' + previous_task_definition)\n\n # Build a map of the original container definitions so that the\n # array index positions can be easily looked up\n container_map = {}\n for index, container_definition in enumerate(container_definitions):\n env_var_map = {}\n env_var_definitions = container_definition.get('environment')\n if env_var_definitions is not None:\n for env_var_index, env_var_definition in enumerate(env_var_definitions):\n env_var_map[env_var_definition['name']] = {'index': env_var_index}\n secret_map = {}\n secret_definitions = container_definition.get('secrets')\n if secret_definitions is not None:\n for secret_index, secret_definition in enumerate(secret_definitions):\n secret_map[secret_definition['name']] = {'index': secret_index}\n container_map[container_definition['name']] = {'image': container_definition['image'], 'index': index, 'environment_map': env_var_map, 'secret_map': secret_map}\n\n # Expected format: container=...,name=...,value=...,container=...,name=...,value=\n try:\n env_kv_pairs = container_env_var_updates.split(',')\n for index, kv_pair in enumerate(env_kv_pairs):\n kv = kv_pair.split('=')\n key = kv[0].strip()\n\n if key == 'container':\n container_name = kv[1].strip()\n env_var_name_kv = env_kv_pairs[index+1].split('=')\n env_var_name = env_var_name_kv[1].strip()\n env_var_value_kv = env_kv_pairs[index+2].split('=', maxsplit=1)\n env_var_value = env_var_value_kv[1].strip()\n if env_var_name_kv[0].strip() != 'name' or env_var_value_kv[0].strip() != 'value':\n raise ValueError(\n 'Environment variable update parameter format is incorrect: ' + container_env_var_updates)\n\n container_entry = container_map.get(container_name)\n if container_entry is None:\n raise ValueError('The container ' + container_name + ' is not defined in the existing task definition')\n container_index = container_entry['index']\n env_var_entry = container_entry['environment_map'].get(env_var_name)\n if env_var_entry is None:\n # The existing container definition does not contain environment variables\n if container_definitions[container_index].get('environment') is None:\n container_definitions[container_index]['environment'] = []\n # This env var does not exist in the existing container definition\n container_definitions[container_index]['environment'].append({'name': env_var_name, 'value': env_var_value})\n else:\n env_var_index = env_var_entry['index']\n container_definitions[container_index]['environment'][env_var_index]['value'] = env_var_value\n elif key and key not in ['container', 'name', 'value']:\n raise ValueError('Incorrect key found in environment variable update parameter: ' + key)\n except ValueError as value_error:\n raise value_error\n except:\n raise Exception('Environment variable update parameter could not be processed; please check parameter value: ' + container_env_var_updates)\n\n # Expected format: container=...,string=...,string=...,container=...,string=...,string=\n \n try:\n docker_label_kv_pairs = container_docker_label_updates.split(',')\n for index, kv_pair in enumerate(docker_label_kv_pairs):\n kv = kv_pair.split('=')\n key = kv[0].strip()\n\n if key == 'container':\n container_name = kv[1].strip()\n docker_label_kv = docker_label_kv_pairs[index+1].split('=')\n docker_label_key = docker_label_kv[0].strip()\n docker_label_value = docker_label_kv[1].strip()\n container_entry = container_map.get(container_name)\n if container_entry is None:\n raise ValueError('The container ' + container_name + ' is not defined in the existing task definition')\n container_index = container_entry['index']\n docker_label_entry = container_entry['environment_map'].get(docker_label_key)\n if docker_label_entry is None:\n # The existing container definition does not contain environment variables\n if container_definitions[container_index].get('dockerLabels') is None:\n container_definitions[container_index]['dockerLabels'] = {}\n # This env var does not exist in the existing container definition\n container_definitions[container_index]['dockerLabels'][docker_label_key] = docker_label_value\n else:\n docker_label_index = docker_label_entry['index']\n container_definitions[container_index]['dockerLabels'][docker_label_index][docker_label_key] = docker_label_value\n except ValueError as value_error:\n raise value_error\n except:\n raise Exception('Docker label update parameter could not be processed; please check parameter value: ' + container_docker_label_updates)\n\n # Expected format: container=...,name=...,valueFrom=...,container=...,name=...,valueFrom=...\n\n try:\n secret_kv_pairs = container_secret_updates.split(',')\n for index, kv_pair in enumerate(secret_kv_pairs):\n kv = kv_pair.split('=')\n key = kv[0].strip()\n if key == 'container':\n container_name = kv[1].strip()\n secret_name_kv = secret_kv_pairs[index+1].split('=')\n secret_name = secret_name_kv[1].strip()\n secret_value_kv = secret_kv_pairs[index+2].split('=', maxsplit=1)\n secret_value = secret_value_kv[1].strip()\n if secret_name_kv[0].strip() != 'name' or secret_value_kv[0].strip() != 'valueFrom':\n raise ValueError(\n 'Container secret update parameter format is incorrect: ' + container_secret_updates)\n\n container_entry = container_map.get(container_name)\n if container_entry is None:\n raise ValueError('The container ' + container_name + ' is not defined in the existing task definition')\n container_index = container_entry['index']\n secret_entry = container_entry['secret_map'].get(secret_name)\n if secret_entry is None:\n # The existing container definition does not contain secrets variable\n if container_definitions[container_index].get('secrets') is None:\n container_definitions[container_index]['secrets'] = []\n # The secrets variable does not exist in the existing container definition\n container_definitions[container_index]['secrets'].append({'name': secret_name, 'valueFrom': secret_value})\n else:\n secret_index = secret_entry['index']\n container_definitions[container_index]['secrets'][secret_index]['valueFrom'] = secret_value\n elif key and key not in ['container', 'name', 'valueFrom']:\n raise ValueError('Incorrect key found in secret updates parameter: ' + key)\n except ValueError as value_error:\n raise value_error\n except:\n raise Exception('Container secrets update parameter could not be processed; please check parameter value: ' + container_secret_updates)\n\n # Expected format: container=...,image-and-tag|image|tag=...,container=...,image-and-tag|image|tag=...,\n try:\n if container_image_name_updates and \"container=\" not in container_image_name_updates:\n raise ValueError('The container parameter is required in the container_image_name_updates variable.')\n\n image_kv_pairs = container_image_name_updates.split(',')\n for index, kv_pair in enumerate(image_kv_pairs):\n kv = kv_pair.split('=')\n key = kv[0].strip()\n if key == 'container':\n container_name = kv[1].strip()\n image_kv = image_kv_pairs[index+1].split('=')\n container_entry = container_map.get(container_name)\n if container_entry is None:\n raise ValueError('The container ' + container_name + ' is not defined in the existing task definition')\n container_index = container_entry['index']\n image_specifier_type = image_kv[0].strip()\n image_value = image_kv[1].strip()\n if image_specifier_type == 'image-and-tag':\n container_definitions[container_index]['image'] = image_value\n else:\n existing_image_name_tokens = container_entry['image'].split(':')\n if image_specifier_type == 'image':\n tag = ''\n if len(existing_image_name_tokens) == 2:\n tag = ':' + existing_image_name_tokens[1]\n container_definitions[container_index]['image'] = image_value + tag\n elif image_specifier_type == 'tag':\n container_definitions[container_index]['image'] = existing_image_name_tokens[0] + ':' + image_value\n else:\n raise ValueError(\n 'Image name update parameter format is incorrect: ' + container_image_name_updates)\n elif key and key not in ['container', 'image', 'image-and-tag', 'tag']:\n raise ValueError('Incorrect key found in image name update parameter: ' + key)\n\n except ValueError as value_error:\n raise value_error\n except:\n raise Exception('Image name update parameter could not be processed; please check parameter value: ' + container_image_name_updates)\n return json.dumps(container_definitions)\n\n\nif __name__ == '__main__':\n try:\n print(run(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]))\n except Exception as e:\n sys.stderr.write(str(e) + \"\\n\")\n exit(1)\n" ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES: << parameters.container_docker_label_updates >> ORB_STR_CONTAINER_ENV_VAR_UPDATE: <<parameters.container_env_var_updates>> ORB_STR_CONTAINER_IMAGE_NAME_UPDATES: <<parameters.container_image_name_updates>> ORB_STR_CONTAINER_SECRET_UPDATES: <<parameters.container_secret_updates>> ORB_STR_FAMILY: <<parameters.family>> ORB_STR_PREVIOUS_REVISION_NUMBER: <<parameters.previous_revision_number>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> name: Retrieve previous task definition and prepare new task definition values - run: command: |- #!/bin/bash set -o noglob # These variables are evaluated so the config file may contain and pass in environment variables to the parameters. ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -n "${CCI_ORB_AWS_ECS_TASK_ROLE}" ]; then set -- "$@" --task-role-arn "${CCI_ORB_AWS_ECS_TASK_ROLE}" fi if [ -n "${CCI_ORB_AWS_ECS_EXECUTION_ROLE}" ]; then set -- "$@" --execution-role-arn "${CCI_ORB_AWS_ECS_EXECUTION_ROLE}" fi if [ -n "${CCI_ORB_AWS_ECS_NETWORK_MODE}" ]; then set -- "$@" --network-mode "${CCI_ORB_AWS_ECS_NETWORK_MODE}" fi if [ -n "${CCI_ORB_AWS_ECS_VOLUMES}" ] && [ "${CCI_ORB_AWS_ECS_VOLUMES}" != "[]" ]; then set -- "$@" --volumes "${CCI_ORB_AWS_ECS_VOLUMES}" fi if [ -n "${CCI_ORB_AWS_ECS_PLACEMENT_CONSTRAINTS}" ] && [ "${CCI_ORB_AWS_ECS_PLACEMENT_CONSTRAINTS}" != "[]" ]; then set -- "$@" --placement-constraints "${CCI_ORB_AWS_ECS_PLACEMENT_CONSTRAINTS}" fi if [ -n "${CCI_ORB_AWS_ECS_REQ_COMP}" ] && [ "${CCI_ORB_AWS_ECS_REQ_COMP}" != "[]" ]; then #shellcheck disable=SC2086 set -- "$@" --requires-compatibilities ${CCI_ORB_AWS_ECS_REQ_COMP} fi if [ -n "${CCI_ORB_AWS_ECS_TASK_CPU}" ]; then set -- "$@" --cpu "${CCI_ORB_AWS_ECS_TASK_CPU}" fi if [ -n "${CCI_ORB_AWS_ECS_TASK_MEMORY}" ]; then set -- "$@" --memory "${CCI_ORB_AWS_ECS_TASK_MEMORY}" fi if [ -n "${CCI_ORB_AWS_ECS_PID_MODE}" ]; then set -- "$@" --pid-mode "${CCI_ORB_AWS_ECS_PID_MODE}" fi if [ -n "${CCI_ORB_AWS_ECS_IPC_MODE}" ]; then set -- "$@" --ipc-mode "${CCI_ORB_AWS_ECS_IPC_MODE}" fi if [ -n "${CCI_ORB_AWS_ECS_TAGS}" ] && [ "${CCI_ORB_AWS_ECS_TAGS}" != "[]" ]; then set -- "$@" --tags "${CCI_ORB_AWS_ECS_TAGS}" fi if [ -n "${CCI_ORB_AWS_ECS_PROXY_CONFIGURATION}" ] && [ "${CCI_ORB_AWS_ECS_PROXY_CONFIGURATION}" != "{}" ]; then set -- "$@" --proxy-configuration "${CCI_ORB_AWS_ECS_PROXY_CONFIGURATION}" fi if [ -n "${CCI_ORB_AWS_ECS_RUNTIME_PLATFORM}" ] && [ "${CCI_ORB_AWS_ECS_RUNTIME_PLATFORM}" != "{}" ]; then set -- "$@" --runtime-platform "${CCI_ORB_AWS_ECS_RUNTIME_PLATFORM}" fi if [ -n "${CCI_ORB_AWS_ECS_EPHEMERAL_STORAGE}" ] && [ "${CCI_ORB_AWS_ECS_EPHEMERAL_STORAGE}" != "{}" ]; then set -- "$@" --ephemeral-storage "${CCI_ORB_AWS_ECS_EPHEMERAL_STORAGE}" fi set -x REVISION=$(aws ecs register-task-definition \ --family "$ORB_STR_FAMILY" \ --container-definitions "${CCI_ORB_AWS_ECS_CONTAINER_DEFS}" \ --profile "${ORB_STR_PROFILE_NAME}" \ "$@" \ --output text \ --region "${ORB_AWS_REGION}" \ --query 'taskDefinition.taskDefinitionArn') echo "Registered task definition: ${REVISION}" echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${REVISION}'" >> "$BASH_ENV" set +x environment: ORB_AWS_REGION: << parameters.region >> ORB_STR_FAMILY: <<parameters.family>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> name: Register new task definition update_task_definition_from_json: description: Registers a task definition based on a json file. parameters: profile_name: default: default description: AWS profile name to be configured. type: string region: default: $AWS_DEFAULT_REGION description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string task_definition_json: description: | Location of your .json task definition file (relative or absolute). type: string steps: - run: command: | #!/bin/bash ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_STR_TASK_DEFINITION_JSON="$(circleci env subst "$ORB_STR_TASK_DEFINITION_JSON")" ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ "${ORB_STR_TASK_DEFINITION_JSON:0:1}" != "/" ]; then ORB_STR_TASK_DEFINITION_JSON="$(pwd)/${ORB_STR_TASK_DEFINITION_JSON}" fi REVISION=$(aws ecs register-task-definition \ --profile "${ORB_STR_PROFILE_NAME}" \ --cli-input-json file://"${ORB_STR_TASK_DEFINITION_JSON}" \ --output text \ --region "${ORB_AWS_REGION}" \ --query 'taskDefinition.taskDefinitionArn' \ "$@") echo "Registered task definition: ${REVISION}" echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${REVISION}'" >> "$BASH_ENV" environment: ORB_AWS_REGION: << parameters.region >> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> ORB_STR_TASK_DEFINITION_JSON: <<parameters.task_definition_json>> name: Register new task definition verify_revision_is_deployed: description: | Polls the service's deployment status at intervals until the given task definition revision is the only one deployed for the service, and for the task definition revision's running task count to match the desired count. Does not support ECS services that are of the Blue/Green Deployment type. parameters: cluster: description: The short name or full ARN of the cluster that hosts the service. type: string fail_on_verification_timeout: default: true description: | Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts. type: boolean family: description: Name of the task definition's family. type: string max_poll_attempts: default: 50 description: The maximum number of attempts to poll for the deployment status before giving up. type: integer poll_interval: default: 20 description: The polling interval, in seconds. type: integer profile_name: default: default description: AWS profile name to be configured. type: string region: default: $AWS_DEFAULT_REGION description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string service_name: default: "" description: The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition. type: string task_definition_arn: description: ARN of the task definition whose deployment status is to be monitored. type: string steps: - run: command: |+ #!/bin/bash # These variables are evaluated so the config file may contain and pass in environment variables to the parameters. ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_SERVICE_NAME="$(circleci env subst "$ORB_STR_SERVICE_NAME")" ORB_STR_CLUSTER_NAME="$(circleci env subst "$ORB_STR_CLUSTER_NAME")" ORB_STR_TASK_DEF_ARN="$(circleci env subst "$ORB_STR_TASK_DEF_ARN")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ "$ORB_STR_TASK_DEF_ARN" = "" ]; then echo "Invalid task-definition-arn parameter value: $ORB_STR_TASK_DEF_ARN" exit 1 fi if [ -z "${ORB_STR_SERVICE_NAME}" ]; then ORB_STR_SERVICE_NAME="$ORB_STR_FAMILY" fi echo "Verifying that $ORB_STR_TASK_DEF_ARN is deployed.." attempt=0 while [ "$attempt" -lt "$ORB_VAL_MAX_POLL_ATTEMPTS" ] do DEPLOYMENTS=$(aws ecs describe-services \ --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ --region "${ORB_AWS_REGION}" \ --output text \ --query 'services[0].deployments[].[taskDefinition, status]' \ "$@") NUM_DEPLOYMENTS=$(aws ecs describe-services \ --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ --region "${ORB_AWS_REGION}" \ --output text \ --query 'length(services[0].deployments)' \ "$@") TARGET_REVISION=$(aws ecs describe-services \ --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ --region "${ORB_AWS_REGION}" \ --output text \ --query "services[0].deployments[?taskDefinition==\`$ORB_STR_TASK_DEF_ARN\` && runningCount == desiredCount && (status == \`PRIMARY\` || status == \`ACTIVE\`)][taskDefinition]" \ "$@") echo "Current deployments: $DEPLOYMENTS" if [ "$NUM_DEPLOYMENTS" = "1" ] && [ "$TARGET_REVISION" = "$ORB_STR_TASK_DEF_ARN" ]; then echo "The task definition revision $TARGET_REVISION is the only deployment for the service and has attained the desired running task count." exit 0 else echo "Waiting for revision $ORB_STR_TASK_DEF_ARN to reach desired running count / older revisions to be stopped.." sleep "$ORB_VAL_POLL_INTERVAL" fi attempt=$((attempt + 1)) done echo "Stopped waiting for deployment to be stable - please check the status of $ORB_STR_TASK_DEF_ARN on the AWS ECS console." if [ "$ORB_VAL_FAIL_ON_VERIFY_TIMEOUT" = "1" ]; then exit 1 fi description: | Poll the deployment status at intervals till the given task definition revision has reached its desired running task count and is the only one deployed for the service. environment: ORB_AWS_REGION: << parameters.region >> ORB_STR_CLUSTER_NAME: <<parameters.cluster>> ORB_STR_FAMILY: <<parameters.family>> ORB_STR_PROFILE_NAME: <<parameters.profile_name>> ORB_STR_SERVICE_NAME: <<parameters.service_name>> ORB_STR_TASK_DEF_ARN: <<parameters.task_definition_arn>> ORB_VAL_FAIL_ON_VERIFY_TIMEOUT: <<parameters.fail_on_verification_timeout>> ORB_VAL_MAX_POLL_ATTEMPTS: <<parameters.max_poll_attempts>> ORB_VAL_POLL_INTERVAL: <<parameters.poll_interval>> name: Verify that the revision is deployed and older revisions are stopped executors: default: description: | A Python Docker image built to run on CircleCI that contains python installed with pyenv and packaging tools pip, pipenv, and poetry. docker: - image: cimg/python:<<parameters.tag>> parameters: resource_class: default: medium description: Configure the executor resource class enum: - small - medium - medium+ - large - xlarge - 2xlarge - 2xlarge+ type: enum tag: default: 3.10.4 description: | Select any of the available tags here: https://circleci.com/developer/images/image/cimg/python. type: string resource_class: <<parameters.resource_class>> jobs: deploy_service_update: description: | Install AWS CLI and update the ECS service with the registered task definition. executor: << parameters.executor >> parameters: auth: description: | The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information. type: steps cluster: description: The short name or full ARN of the cluster that hosts the service. type: string codedeploy_application_name: default: "" description: | The name of the AWS CodeDeploy application used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_capacity_provider_base: default: "" description: | The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and capacity-provider-weight. type: string codedeploy_capacity_provider_name: default: "" description: | The name of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with capacity-provider-base and capacity-provider-weight. type: string codedeploy_capacity_provider_weight: default: "" description: | The base of AWS Capacity Provider to be added to CodeDeploy deployment. Must be used with codedeploy_capacity_provider_name and capacity-provider-base. type: string codedeploy_deployment_group_name: default: "" description: | The name of the AWS CodeDeploy deployment group used for the deployment. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_load_balanced_container_name: default: "" description: | The name of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string codedeploy_load_balanced_container_port: default: "80" description: | The port of the container to be load-balanced via AWS CodeDeploy. Only effective when the deployment_controller parameter value is "CODE_DEPLOY". type: string container_docker_label_updates: default: "" description: | Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas. type: string container_env_var_updates: default: "" description: | Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas. type: string container_image_name_updates: default: "" description: | Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used. type: string container_secret_updates: default: "" description: | Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas. type: string deployment_config_name: default: "" description: | The name of a CODE DEPLOY deployment configuration associated with the IAM user or AWS account. If not specified, the value configured in the deployment group is used as the default. type: string deployment_controller: default: ECS description: The deployment controller to use for the service. Defaulted to ECS enum: - ECS - CODE_DEPLOY type: enum enable_circuit_breaker: default: false description: | Determines whether a service deployment will fail if the service can’t reach a steady state. The deployment circuit breaker can only be used for services using the rolling update (ECS ) deployment type. type: boolean executor: default: default description: The executor to use for this job. By default, this will use the "default" executor provided by this orb. type: executor fail_on_verification_timeout: default: true description: | Whether to exit with an error if the verification of the deployment status does not complete within the number of polling attempts. Only in use when verify_revision_is_deployed is set to true. type: boolean family: description: Name of the task definition's family. type: string force_new_deployment: default: false description: | Whether to force a new deployment of the service. Not applicable to ECS services that are of the Blue/Green Deployment type. type: boolean max_poll_attempts: default: 50 description: | The maximum number of attempts to poll the deployment status before giving up. Only in use when verify_revision_is_deployed is set to true. type: integer poll_interval: default: 20 description: | The polling interval, in seconds. Only in use when verify_revision_is_deployed is set to true. type: integer profile_name: default: default description: AWS profile name to be configured. type: string region: default: ${AWS_DEFAULT_REGION} description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string service_name: default: "" description: The name of the service to update. If undefined, we assume `family` is the name of both the service and task definition. type: string skip_task_definition_registration: default: false description: | Whether to skip registration of a new task definition. type: boolean task_definition_tags: default: "" description: | The metadata that you apply to the task definition to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. (Existing environment variables not included in this parameter will not be removed) Expected formats: - Shorthand Syntax key=string,value=string ... - JSON Syntax [{"key": "string","value": "string"} ... ] Values should not contain commas. type: string verification_timeout: default: 10m description: | The maximum amount of time to wait for a blue/green deployment to complete before timing out. Only in use when the deployment controller is the blue/green deployment type. type: string verify_revision_is_deployed: default: false description: | Runs the verify_revision_is_deployed Orb command to verify that the revision has been deployed and is the only deployed revision for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached. type: boolean steps: - steps: << parameters.auth >> - update_service: cluster: << parameters.cluster >> codedeploy_application_name: << parameters.codedeploy_application_name >> codedeploy_capacity_provider_base: <<parameters.codedeploy_capacity_provider_base>> codedeploy_capacity_provider_name: <<parameters.codedeploy_capacity_provider_name>> codedeploy_capacity_provider_weight: <<parameters.codedeploy_capacity_provider_weight>> codedeploy_deployment_group_name: << parameters.codedeploy_deployment_group_name >> codedeploy_load_balanced_container_name: << parameters.codedeploy_load_balanced_container_name >> codedeploy_load_balanced_container_port: << parameters.codedeploy_load_balanced_container_port >> container_docker_label_updates: << parameters.container_docker_label_updates >> container_env_var_updates: << parameters.container_env_var_updates >> container_image_name_updates: << parameters.container_image_name_updates >> container_secret_updates: << parameters.container_secret_updates >> deployment_config_name: <<parameters.deployment_config_name>> deployment_controller: << parameters.deployment_controller >> enable_circuit_breaker: << parameters.enable_circuit_breaker >> fail_on_verification_timeout: << parameters.fail_on_verification_timeout >> family: << parameters.family >> force_new_deployment: << parameters.force_new_deployment >> max_poll_attempts: << parameters.max_poll_attempts >> poll_interval: << parameters.poll_interval >> profile_name: << parameters.profile_name >> region: << parameters.region >> service_name: << parameters.service_name >> skip_task_definition_registration: << parameters.skip_task_definition_registration >> task_definition_tags: << parameters.task_definition_tags >> verification_timeout: << parameters.verification_timeout >> verify_revision_is_deployed: << parameters.verify_revision_is_deployed >> run_task: description: | Install AWS CLI and Start a new ECS task using the specified task definition and other parameters. executor: << parameters.executor >> parameters: assign_public_ip: default: DISABLED description: | "Assign a public IP or not" enum: - ENABLED - DISABLED type: enum auth: description: | The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information. type: steps awsvpc: default: true description: | "Does your task definition use awsvpc mode or not. If so, this should be true and you should also include subnet_ids and optionally security_group_ids / assign_public_ips." type: boolean capacity_provider_strategy: default: "" description: | The capacity provider strategy to use for the task. If a `capacity_provider_strategy` is specified, the `launch_type` parameter must be set to an empty string. type: string cluster: description: The name or ARN of the cluster on which to run the task. type: string count: default: 1 description: | "The number of instantiations of the specified task to place on your cluster. You can specify up to 10 tasks per call." type: integer enable_ecs_managed_tags: default: false description: | "Specifies whether to enable Amazon ECS managed tags for the task." type: boolean enable_execute_command: default: false description: | Determines whether to use the execute command functionality for the containers in this task. If true, this enables execute command functionality on all containers in the task. type: boolean executor: default: default description: The executor to use for this job. By default, this will use the "default" executor provided by this orb. type: executor group: default: "" description: | The name of the task group to associate with the task. The default value is the family name of the task definition (for example, family:my_family_name). type: string launch_type: default: FARGATE description: | The launch type on which to run your task. Possible values EC2, FARGATE, or an empty string. For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide. enum: - FARGATE - EC2 - "" type: enum overrides: default: "" description: | A list of container overrides in JSON format that specify the name of a container in the specified task definition and the overrides it should receive. type: string placement_constraints: default: "" description: | "An array of placement constraint objects to use for the task. You can specify up to 10 constraints per task (including constraints in the task definition and those specified at runtime). Expected format: type=string,field=string." type: string placement_strategy: default: "" description: | "The placement strategy objects to use for the task. You can specify a maximum of five strategy rules per task. Expected format: type=string,field=string." type: string platform_version: default: "" description: | Use this to specify the platform version that the task should run on. A platform version should only be specified for tasks using the Fargate launch type. type: string profile_name: default: default description: AWS profile name to be configured. type: string propagate_tags: default: false description: | "Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action." type: boolean region: default: ${AWS_DEFAULT_REGION} description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string run_task_output: default: "" description: | Specifies a local json file to save the output logs from the aws ecs run_task command. Use tools like JQ to read and parse this information such as "task-arns" and "task-ids" type: string security_group_ids: default: "" description: | "List of security group ids separated by commas. Expected Format: sg-010a460f7f442fa75,sg-010a420f7faa5fa75" type: string started_by: default: "" description: | An optional tag specified when a task is started. For example, if you automatically trigger a task to run a batch process job, you could apply a unique identifier for that job to your task with the startedBy parameter. You can then identify which tasks belong to that job by filtering the results of a ListTasks call with the startedBy value. Up to 36 letters (uppercase and lowercase), num- bers, hyphens, and underscores are allowed. type: string subnet_ids: default: "" description: | "List of subnet ids separated by commas. Expected Format: subnet-70faa93b,subnet-bcc54b93" type: string tags: default: "" description: | "The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Expected format: key=string,value=string." type: string task_definition: description: | "The family and revision (family:revision) or full ARN of the task definition to run. If a revision is not specified, the latest ACTIVE revision is used." type: string steps: - steps: << parameters.auth >> - run_task: assign_public_ip: << parameters.assign_public_ip >> awsvpc: << parameters.awsvpc >> capacity_provider_strategy: << parameters.capacity_provider_strategy >> cluster: << parameters.cluster >> count: << parameters.count >> enable_ecs_managed_tags: << parameters.enable_ecs_managed_tags >> enable_execute_command: << parameters.enable_execute_command>> group: << parameters.group >> launch_type: << parameters.launch_type >> overrides: << parameters.overrides >> placement_constraints: << parameters.placement_constraints >> placement_strategy: << parameters.placement_strategy >> platform_version: << parameters.platform_version >> profile_name: << parameters.profile_name >> propagate_tags: << parameters.propagate_tags >> region: << parameters.region >> run_task_output: <<parameters.run_task_output>> security_group_ids: << parameters.security_group_ids >> started_by: << parameters.started_by >> subnet_ids: << parameters.subnet_ids >> tags: << parameters.tags >> task_definition: << parameters.task_definition >> update_task_definition: description: | Install AWS CLI and register a task definition. executor: << parameters.executor >> parameters: auth: description: | The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information. type: steps container_docker_label_updates: default: "" description: | Use this to update or set the values of docker label variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,<key>=<env-var-name>,<key>=<env-var-value>,container=...,<key>=...,<key>=..., Values should not contain commas. type: string container_env_var_updates: default: "" description: | Use this to update or set the values of environment variables that will be defined for the containers. (Existing environment variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,value=<env-var-value>,container=...,name=...,value=..., Values should not contain commas. type: string container_image_name_updates: default: "" description: | Use this to update the Docker image names and/or tag names of existing containers that had been defined in the previous task definition. Expected format: container=<container-name>,image-and-tag=<image-name>:<tag-name>|image=<image-name>|tag=<tag-name>,container=...,image-and-tag|image|tag=..., For each container, specify only either "image-and-tag" or "image" or "tag". If "image-and-tag" is specified, the container image will be updated to the value of the name-value pair. If "image" is specified, the image tag defined in the previous task definition will be retained, if exists. If "tag" is specified, the image name defined in the previous task definition will be used. type: string container_secret_updates: default: "" description: | Use this to update or set the values of secrets variables that will be defined for the containers. (Existing secrets variables not included in this parameter will not be removed) Expected format: container=<container-name>,name=<env-var-name>,valueFrom=<env-var-value>,container=...,name=...,valueFrom=..., Values should not contain commas. type: string deploy_scheduled_task: default: false description: | Set this parameter to true to deploy updated task definition to a scheduled task rule. type: boolean executor: default: default description: The executor to use for this job. By default, this will use the "default" executor provided by this orb. type: executor family: description: Name of the task definition's family. type: string profile_name: default: default description: AWS profile name to be configured. type: string region: default: ${AWS_DEFAULT_REGION} description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string rule_name: default: "" description: The name of the scheduled task's rule to update. Must be a valid ECS Rule. type: string steps: - steps: << parameters.auth >> - update_task_definition: container_docker_label_updates: << parameters.container_docker_label_updates >> container_env_var_updates: << parameters.container_env_var_updates >> container_image_name_updates: << parameters.container_image_name_updates >> container_secret_updates: << parameters.container_secret_updates >> family: << parameters.family >> profile_name: << parameters.profile_name >> region: << parameters.region >> - when: condition: <<parameters.deploy_scheduled_task>> steps: - deploy_ecs_scheduled_task: region: << parameters.region >> rule_name: <<parameters.rule_name>> update_task_definition_from_json: description: | Install AWS CLI and a task definition from a json file. executor: << parameters.executor >> parameters: auth: description: | The authentication method used to access your AWS account. Import the aws-cli orb in your config and provide the aws-cli/setup command to authenticate with your preferred method. View examples for more information. type: steps deploy_scheduled_task: default: false description: | Set this parameter to true to deploy updated task definition to a scheduled task rule. type: boolean executor: default: default description: The executor to use for this job. By default, this will use the "default" executor provided by this orb. type: executor profile_name: default: default description: AWS profile name to be configured. type: string region: default: ${AWS_DEFAULT_REGION} description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable. type: string rule_name: description: The name of the scheduled task's rule to update. Must be a valid ECS Rule. type: string task_definition_json: description: | Location of your .json task definition file (relative or absolute). type: string steps: - steps: << parameters.auth >> - update_task_definition_from_json: profile_name: << parameters.profile_name >> region: << parameters.region >> task_definition_json: << parameters.task_definition_json >> - when: condition: <<parameters.deploy_scheduled_task>> steps: - deploy_ecs_scheduled_task: region: << parameters.region >> rule_name: <<parameters.rule_name>> examples: deploy_ecs_scheduled_task: description: | Use the AWS CLI and this orb to deploy an ECS Scheduled Task Rule after updating a task definition. The update_task_definition or update_task_definition_from_json command must be run first. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: deploy_scheduled_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: us-east-1 role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: "3600" - aws-ecs/update_task_definition_from_json: region: us-east-1 task_definition_json: my-app-definition.json - aws-ecs/deploy_ecs_scheduled_task: region: us-east-1 rule_name: example-rule workflows: deploy: jobs: - deploy_scheduled_task: context: - CircleCI_OIDC_Token deploy_service_update: description: | Update an ECS service using OIDC for authentication. Import the aws-cli orb and authenticate using the aws-cli/setup command with a valid role_arn for OIDC authentication. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecr: circleci/aws-ecr@9.3.4 aws-ecs: circleci/aws-ecs@6.0.0 workflows: build-and-deploy: jobs: - aws-ecr/build_and_push_image: auth: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECR_ROLE profile_name: OIDC-USER region: AWS_REGION repo: ${MY_APP_PREFIX} tag: ${CIRCLE_SHA1} - aws-ecs/deploy_service_update: auth: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE cluster: ${MY_APP_PREFIX}-cluster container_image_name_updates: container=${MY_APP_PREFIX}-service,tag=${CIRCLE_SHA1} family: ${MY_APP_PREFIX}-service profile_name: OIDC-USER region: us-east-1 requires: - aws-ecr/build_and_push_image run_task_ec2: description: Start the run of an ECS task on EC2. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: awsvpc: false cluster: cluster1 launch_type: EC2 region: us-east-1 task_definition: myapp workflows: run_task: jobs: - run_task run_task_fargate: description: Start the run of an ECS task on Fargate. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: cluster: cluster1 region: us-east-1 security_group_ids: $SECURITY_GROUP_IDS subnet_ids: $SUBNET_ONE, $SUBNET_TWO task_definition: myapp workflows: run_task: jobs: - run_task run_task_fargate_spot: description: | Amazon Fargate Spot Instances let you take advantage of spare compute capacity in the AWS Cloud at steep discounts. Fargate Spot is an AWS Fargate capability that can run interruption-tolerant Amazon Elastic Container Service (Amazon ECS) tasks at up to a 70% discount off the Fargate price. Since tasks can still be interrupted, only fault tolerant applications are suitable for Fargate Spot. CircleCI provides continuous integration and delivery for any platform, as well as your own infrastructure. CircleCI can automatically trigger low-cost, serverless tasks with AWS Fargate Spot in Amazon ECS. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: run_task: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-USER role_arn: arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE - aws-ecs/run_task: capacity_provider_strategy: capacityProvider=FARGATE,weight=1 capacityProvider=FARGATE_SPOT,weight=1 cluster: $CLUSTER_NAME launch_type: "" region: us-east-1 security_group_ids: $SECURITY_GROUP_IDS_FETCHED subnet_ids: $SUBNET_ONE, $SUBNET_TWO task_definition: $My_Task_Def workflows: run_task: jobs: - run_task update_service: description: | Use the AWS CLI and this orb to update an ECS service. (Supports both EC2 and Fargate launch types) usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: update-tag: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: "3600" - aws-ecs/update_service: cluster: ${MY_APP_PREFIX}-cluster container_image_name_updates: container=${MY_APP_PREFIX}-service,tag=stable family: ${MY_APP_PREFIX}-service region: us-east-1 workflows: deploy: jobs: - update-tag: context: - CircleCI_OIDC_Token update_task_definition_from_json: description: Use the AWS CLI and this orb to create a new ECS task definition based upon a local JSON file. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: update-tag: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: "3600" - aws-ecs/update_task_definition_from_json: region: us-east-1 task_definition_json: my-app-definition.json workflows: deploy: jobs: - update-tag: context: - CircleCI_OIDC_Token verify_revision_deployment: description: Verify the deployment of an ECS revision. usage: version: "2.1" orbs: aws-cli: circleci/aws-cli@5.1.0 aws-ecs: circleci/aws-ecs@6.0.0 jobs: verify-deployment: docker: - image: cimg/python:3.10 steps: - aws-cli/setup: profile_name: OIDC-PROFILE region: AWS_REGION role_arn: arn:aws:iam::123456789012:role/OIDC_ARN role_session_name: example-session-name session_duration: "3600" - run: command: | TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ --task_definition ${MY_APP_PREFIX}-service \ --output text \ --query 'taskDefinition.taskDefinitionArn' \ --profile default \ --region ${AWS_DEFAULT_REGION}) echo "export TASK_DEFINITION_ARN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV name: Get last task definition - aws-ecs/verify_revision_is_deployed: cluster: ${MY_APP_PREFIX}-cluster family: ${MY_APP_PREFIX}-service region: us-east-1 task_definition_arn: ${TASK_DEFINITION_ARN} workflows: test-workflow: jobs: - verify-deployment: context: - CircleCI_OIDC_Token
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.