Amazon ECS Render Task Definition GitHub Action

repository·master·Indexed 43 days ago

https://github.com/aws-actions/amazon-ecs-render-task-definition

A GitHub Action (v1.9.0) that automates updating Amazon ECS task definitions with new container images, environment variables, secrets, and log configurations. It allows users to render a new task definition JSON file from a local file, ARN, or family, which can then be used for continuous deployment workflows.

Tokens
2.7K
Snippets
6
Records
8
Agent score
6%

What's inside Amazon ECS Render Task Definition

  1. Use the Amazon ECS Render Task Definition Action

    master

    The amazon-ecs-render-task-definition action inserts a new container image URI into an existing Amazon ECS task definition JSON file. This creates a new, modified task definition file that can then be used for deployment.

    Task Definition Source Precedence

    The action requires a way to identify the task definition. The precedence for fetching the task definition is as follows:

    1. task-definition (file path): If a file is provided, it takes precedence over all other options. If both a file and an ARN are provided, a warning is issued and the file is used.
    2. task-definition-arn
    3. task-definition-family

    Note: If none of these three options are provided, the action will throw an error.

        - name: Render Amazon ECS task definition
          id: render-web-container
          uses: aws-actions/amazon-ecs-render-task-definition@v1
          with:
            task-definition: task-definition.json
            container-name: web
            image: amazon/amazon-ecs-sample:latest
  2. Update Environment Variables and Secrets

    master

    You can inject environment variables or secrets into a container definition using newline-delimited strings. The action will either update an existing variable/secret if the name matches or append a new one if it does not.

    Environment Variables Format:

    KEY1=value1
    KEY2=value2

    Secrets Format:

    SECRET_NAME=arn:aws:secretsmanager:region:account:secret:name
  3. Configure Amazon ECS Task Definition Rendering

    master

    The amazon-ecs-render-task-definition action allows you to take an existing ECS task definition (either from a local JSON file or by fetching it from AWS via ARN, family, or revision) and render a new version with updated container images, environment variables, secrets, and other configurations.

    To use this action, you must provide a source for the task definition and specify which container(s) to update.

    - name: Render Amazon ECS task definition
      uses: aws-actions/amazon-ecs-render-task-definition@v1
      with:
        task-definition: task-definition.json
        container-name: my-container
        image: my-new-image:latest
  4. Update multiple containers in a single task definition

    master

    If your task definition contains multiple containers in the containerDefinitions section that each require different image URIs, you must chain multiple executions of this action. Use the output from the first action as the task-definition input for the subsequent action(s).

    To use the resulting file for deployment, pass the output from the final rendering step to your deployment action.

        - name: Render Amazon ECS task definition for first container
          id: render-web-container
          uses: aws-actions/amazon-ecs-render-task-definition@v1
          with:
            task-definition: task-definition.json
            container-name: web
            image: amazon/amazon-ecs-sample-1:latest
            environment-variables: |
                LOG_LEVEL=info
                ENVIRONMENT=prod
            docker-labels: |
                SERVICE=service
                VERSION=version
            secrets: |
                SECRET_KEY=arn:aws:ssm:region:0123456789:parameter/secret
                SECOND_SECRET_KEY=arn:aws:secretsmanager:us-east-1:0123456789:secret:secretName
    
        - name: Modify Amazon ECS task definition with second container
          id: render-app-container
          uses: aws-actions/amazon-ecs-render-task-definition@v1
          with:
            task-definition: ${{ steps.render-web-container.outputs.task-definition }}
            container-name: app
            image: amazon/amazon-ecs-sample-2:latest
    
        - name: Deploy to Amazon ECS service
          uses: aws-actions/amazon-ecs-deploy-task-definition@v2
          with:
            task-definition: ${{ steps.render-app-container.outputs.task-definition }}
            service: my-service
            cluster: my-cluster
  5. Configure ECS log driver and options

    master

    You can configure the log driver for a container by using log-configuration-log-driver and log-configuration-options. The options should be provided as a multi-line string where each line contains a key=value pair.

        - name: Render Amazon ECS task definition
          id: render-web-container
          uses: aws-actions/amazon-ecs-render-task-definition@v1
          with:
            task-definition: task-definition.json
            container-name: web
            image: amazon/amazon-ecs-sample:latest
            log-configuration-log-driver: awslogs
            log-configuration-options: |
              awslogs-create-group=true
              awslogs-group=/ecs/web
              awslogs-region=us-east-1
              awslogs-stream-prefix=ecs
  6. Reference: Task Definition Input Parameters

    master

    These inputs define how the action fetches the base task definition and which specific container properties are updated.

    ### Task Definition Source
    - `task-definition`: (Optional) Path to a local JSON task definition file. If provided, this takes precedence over AWS-based fetching.
    - `task-definition-arn`: (Optional) The ARN of the task definition to fetch from AWS.
    - `task-definition-family`: (Optional) The family name of the task definition to fetch from AWS.
    - `task-definition-revision`: (Optional) The specific revision number to fetch (used with `task-definition-family`).
    
    ### Container Updates
    - `container-name`: (Required) The name of the container to update. Supports a single name or a comma-separated list of names.
    - `image`: (Required) The new image URI to apply to the specified container(s).
    - `command`: (Optional) The command to override for the container. Provided as a space-separated string (e.g., `"python app.py"`).
    - `environment-variables`: (Optional) New environment variables in `NAME=value` format, one per line.
    - `secrets`: (Optional) New secrets in `NAME=valueFrom` format, where `valueFrom` is an ARN from Parameter Store or Secrets Manager. One per line.
    - `env-files`: (Optional) S3 environment files. One S3 path per line.
    - `docker-labels`: (Optional) Docker labels in `key=value` format, one per line.
    - `log-configuration-log-driver`: (Optional) The log driver (e.g., `awslogs`, `json-file`, `splunk`).
    - `log-configuration-options`: (Optional) Log driver options in `key=value` format, one per line.
    
    ### Task-Level Updates
    - `task-role-arn`: (Optional) The ARN for the task role.
    - `execution-role-arn`: (Optional) The ARN for the execution role.
  7. Reference: Log Configuration Options

    master

    The action supports updating the logConfiguration for the specified container(s).

    ### Log Configuration
    - `log-configuration-log-driver`: Valid options include: `json-file`, `syslog`, `journald`, `logentries`, `gelf`, `fluentd`, `awslogs`, `splunk`, `awsfirelens`.
    - `log-configuration-options`: Key-value pairs for the driver, one per line (e.g., `awslogs-group=/ecs/my-app`).