Deploy to AWS

7 minute read

Deploy to Amazon EC2, ECS, Elastic Beanstalk, CodeDeploy, and Lambda using CloudBees AWS deployment actions.

Lambda actions require AWS credentials to be configured before use. Add the following step before invoking any Lambda action in your YAML file:
- name: Configure AWS credentials uses: https://github.com/cloudbees-io/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.MY_KEY_ID }} aws-secret-access-key: ${{ secrets.MY_SECRET_KEY }} aws-region: eu-west-3

Deploy a binary with Amazon EC2

Use the cloudbees-io/ec2-deploy-binary action to copy files to an Amazon EC2 host and optionally execute a command or script after deployment.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 1. Input details
Input name Data type Required? Description

aws-host

String

Yes

The Amazon EC2 host URL.

aws-ssh-key-data

String

Yes

The AWS SSH key data.

aws-user

String

Yes

The AWS user to connect as.

source-location

String

Yes

The source location to copy files from.

destination-ec2-location

String

Yes

The destination location in the Amazon EC2 host.

deploy-command

String

No

The command to execute after deploying to the destination location.

deploy-script

String

No

The script file to execute after deploying to the destination location.

Usage example

In your YAML file, add:

- name: Deploy EC2 binary uses: https://github.com/cloudbees-io/ec2-deploy-binary@v1 with: source-location: workspace/test/* destination-ec2-location: /home/ubuntu/mydeploys/helloworld/ aws-ssh-key-data: ${{ secrets.AWS-DEPLOY-KEY }} aws-user: ubuntu aws-host: ${{ secrets.AWS-HOST }} deploy-script: script1.sh

Render an ECS task definition

Use the cloudbees-io/ecs-render-task-definition action to render an Amazon ECS task definition by injecting a container image and optional environment variables into an existing definition.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 2. Input details
Input name Data type Required? Description

task-definition-name

String

Required only if task-definition is not specified.

The ECS task definition name.

task-definition

String

Required only if task-definition-name is not specified.

The path to the ECS task definition JSON file.

container-name

String

Yes

The container name as defined in the ECS task definition (in containerDefinitions).

image

String

Yes

The container image URL.

environment-variables

JSON

No

Container variables, formatted as JSON data in key/value pairs.

environment-variables-path

String

No

The path of the file that contains the environment variables.

Usage example

In your YAML file, add:

- name: Render task definition uses: https://github.com/cloudbees-io/ecs-render-task-definition@v1 with: task-definition: test/taskDefinition.json container-name: container_name image: ${{ vars.IMAGE_URL }} environment-variables: '{"LOG_LEVEL"="info","ENVIRONMENT"="prod"}' environment-variables-path: sample/example.json

Deploy to Amazon ECS

Use the cloudbees-io/ecs-deploy-task-definition action to deploy to an Amazon ECS cluster using either a service name or a task definition.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 3. Input details
Input name Data type Required? Description

task-definition

String

Required only if service is not specified.

The path to the ECS task definition JSON file.

service

String

Required only if task-definition is not specified.

The name of the ECS service to deploy to.

cluster

String

Yes

The name of the ECS cluster to deploy to.

wait-for-service-stability

Boolean

Yes

Whether to wait for the ECS service to reach a stable state after deploying the new task definition. Default value is false. When false, there is no waiting.

wait-for-minutes

String

Yes

The amount of time to wait for the ECS service to reach a stable state, in minutes. The default is 30 minutes, and the maximum time allowed is 6 hours.

force-new-deployment

Boolean

Yes

Whether to force a new service deployment. Default value is false. When false, the new deployment is not forced.

Usage example

In your YAML file, add:

- name: Deploy task definition uses: https://github.com/cloudbees-io/ecs-deploy-task-definition@v1 with: task-definition: test/taskDefinition.json service: ECS_service_name cluster: ECS_cluster_name wait-for-service-stability: true wait-for-minutes: 6 hours force-new-deployment: true

Deploy with Elastic Beanstalk

Use the cloudbees-io/aws-elastic-beanstalk-invoke-deployment action to create a new application version from a source bundle and update an AWS Elastic Beanstalk environment.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 4. Input details
Input name Data type Required? Description

application-name

String

Yes

The Elastic Beanstalk application name.

s3-bucket

String

Yes

The S3 bucket name.

s3-key

String

Yes

The S3 key for the source bundle.

version-label

String

Yes

The Elastic Beanstalk application version label to be created from the source bundle.

environment-name

String

Yes

The name of the Elastic Beanstalk environment to be updated.

Usage example

In your YAML file, add:

- name: Update Elastic Beanstalk environment uses: https://github.com/cloudbees-io/aws-elastic-beanstalk-invoke-deployment@v1 with: application-name: your-elastic-beanstalk-application s3-bucket: your-s3-bucket s3-key: your-s3-key-for-the-source-bundle version-label: your-application-version-to-be-created environment-name: your-elastic-beanstalk-environment-to-be-updated

Deploy with CodeDeploy

Use the cloudbees-io/aws-codedeploy-invoke-deployment action to trigger an AWS CodeDeploy deployment and retrieve the run information as output.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 5. Input details
Input name Data type Required? Description

application-name

String

Yes

The AWS CodeDeploy application name.

deployment-config-name

String

Yes

The name of the deployment configuration.

deployment-group-name

String

Yes

The name of the deployment group.

description

String

Yes

Additional information about the deployment.

revision-type

String

Yes

The type of application revision.

auto-rollback-enabled

String

No

The configuration for an automatic rollback, added when a deployment is created.

auto-rollback-events

JSON

No

The event type or types that trigger a rollback.

file-exists-behavior

String

No

How AWS CodeDeploy handles files that already exist in a deployment target location but were not part of the previous successful deployment.

ignore-application-stop-failures

Boolean

No

If an ApplicationStop, BeforeBlockTraffic, or AfterBlockTraffic deployment lifecycle event on an instance fails, and ignore-application-stop-failures: true, the deployment continues to the next deployment lifecycle event.

override-alarm-names

JSON

No

A list of alarms configured for the deployment or deployment group.

override-alarm-enabled

String

No

Indicates whether the alarm configuration is enabled.

appspec-content

String

No

The content of an AppSpec file for an AWS Lambda or Amazon ECS deployment. The content is formatted as JSON or YAML and stored as a RawString.

appspec-sha256

String

No

The SHA256 hash value of the revision content.

string-content

String

No

The content of a string input for an AWS Lambda or Amazon ECS deployment. The content is formatted as JSON or YAML and stored as a RawString.

string-sha256

String

No

The SHA256 hash value of the revision content.

github-commit-id

String

No

The SHA1 commit ID of the GitHub commit that represents the bundled artifacts for the application revision.

github-repository

String

No

The GitHub account and repository pair that stores a reference to the commit that represents the bundled artifacts for the application revision.

s3-bucket

String

No

The name of the Amazon S3 bucket where the application revision is stored.

s3-bundle-type

String

No

The file type of the application revision.

s3-key

String

No

The name of the Amazon S3 object that represents the bundled artifacts for the application revision.

s3-artifact-version

String

No

The specific version of the Amazon S3 object that represents the bundled artifacts for the application revision.

target-auto-scaling-groups

JSON

No

The names of one or more Auto Scaling groups to identify a replacement environment for a blue or green deployment.

target-instance-tag-filters

JSON

No

The tag filter key, type, and value used to identify Amazon EC2 instances in a replacement environment for a blue or green deployment.

target-instance-tag-set

JSON

No

The information about the groups of Amazon EC2 instance tags.

Usage example

In your YAML file, add:

- id: login name: Configure AWS credentials uses: https://github.com/cloudbees-io/configure-aws-credentials@v1 with: aws-region: us-east-1 aws-access-key-id: ${{ secrets.AWS_CODEDEPLOY_ACTIONS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_CODEDEPLOY_ACTIONS_SECRET_ACCESS_KEY }} - name: Create AWS CodeDeploy deployment uses: https://github.com/cloudbees-io/aws-codedeploy-invoke-deployment@v1 with: application-name: 'cb-sample-app' description: "CodeDeploy-ec2-deployment" deployment-group-name: 'cd-deployment-grp' revision-type: 'S3' s3-bucket: 'cb-codedeploy' s3-key: 'Archive.zip' s3-bundle-type: 'zip' deployment-config-name: 'CodeDeployDefault.OneAtATime' target-instance-tag-filters: '[{"Key":"Name","Type":"KEY_AND_VALUE","Value":"cb-codedeploy-web"}]'

Create or update a Lambda function

Use the cloudbees-io/lambda-create-function action to create or update a function in AWS Lambda without provisioning or managing servers.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 6. Input details
Input name Data type Required? Description

function-name

String

Yes

The AWS Lambda function name.

iam-role-arn

String

Yes

The Identity and Access Management (IAM) name of the function’s execution role, in ARN format.

package-type

String

No

The type of build input artifact. Options are Zip (ZIP file) and Image (container image).

code-image

String

Required only if using an image (package-type: Image).

The code image resource, such as the Amazon ECR repository URI.

code-zip

String

Required only if using a ZIP file (package-type: Zip).

The path to the ZIP file of the code to be uploaded.

handler

String

Required only if using a ZIP file (package-type: Zip).

The method name in uploaded code that Lambda calls to run the function.

runtime

String

Required only if using a ZIP file (package-type: Zip).

The Lambda function runtime.

s3-bucket

String

Required only if using an Amazon S3 bucket.

The Amazon S3 bucket name.

s3-key

String

Required only if using an Amazon S3 bucket.

The Amazon S3 bucket object name.

architectures

JSON string

No

The instruction set architecture that the function supports.

code-signing-config-arn

String

No

The Amazon Resource Name (ARN) for a code-signing configuration.

dead-letter-config

JSON string

No

The location where the Lambda function sends asynchronous events that fail to process.

desc

String

No

The Lambda function description.

dry-run

Boolean

No

Default is false. Enables preview of changes to AWS CLI operations before applying the changes.

environment

JSON string

No

The environment variables accessible from the function code during execution.

ephemeral-storage

JSON string

No

The size of the Lambda function /tmp directory.

file-system-configs

JSON string

No

The Amazon EFS file system connection settings.

image-config

JSON string

No

The container image configuration values that override the container image Dockerfile values.

kms-key-arn

String

No

The ARN of the AWS Key Management Service (KMS) customer-managed key used to encrypt your function’s environment variables.

layers

JSON string

No

The list of function layers to add to the Lambda function’s execution environment.

memory-size

Integer

No

The amount of memory available to the Lambda function at runtime.

publish

Boolean

No

Default is true. Enables the first created version of the Lambda function.

revision-id

String

No

The latest updated revision ID. If specified, the Lambda function is only updated if the revision ID matches the latest updated revision ID.

s3-object-version

String

No

The Amazon S3 bucket object version.

snap-start

JSON string

No

The SnapStart configuration to run the Lambda function with a pre-initialized snapshot.

tags

JSON string

No

The Lambda function tag list.

timeout

Integer

No

The allowed amount of time, in seconds, that a Lambda function runs before it is stopped.

tracing-config

JSON string

No

The AWS X-Ray tracing configuration in the Lambda function. To sample and record incoming requests, enable X-Ray active tracing in the Lambda functions console.

vpc-config

JSON string

No

The VPC security groups and subnets for network connectivity to AWS resources.

Usage examples

The following examples show how to create or update a Lambda function using an ECR image, an Amazon S3 bucket, or a local ZIP file.

Using an ECR image

- name: Create or update AWS lambda function with ECR id: createOrUpdateLambdaFunctionWithECR uses: https://github.com/cloudbees-io/lambda-create-function@v1 with: iam-role-arn: arn:aws:iam::123456789012:role/my-lambda-actions function-name: my-function package-type: Image code-image: 123456789012.dkr.ecr.us-west-2.amazonaws.com/hello-world-lambda:v1 architectures: '["x86_64"]'

Using an Amazon S3 bucket

- name: Create or update an AWS lambda function with S3 id: createOrUpdateLambdaFunctionWithS3 uses: https://github.com/cloudbees-io/lambda-create-function@v1 with: iam-role-arn: arn:aws:iam::123456789012:role/my-lambda-actions function-name: my-function package-type: Zip handler: bootstrap s3-bucket: my-lambda-actions s3-key: hello-lambda/bootstrap.zip s3-object-version: "" architectures: '["x86_64"]' runtime: provided.al2

Using a local ZIP file

- name: Create or update AWS lambda function with ZIP file id: createOrUpdateLambdaFunctionWithZip uses: https://github.com/cloudbees-io/lambda-create-function@v1 with: iam-role-arn: arn:aws:iam::123456789012:role/my-lambda-actions function-name: my-function package-type: Zip handler: bootstrap code-zip: ${{ cloudbees.workspace }}/bootstrap.zip architectures: '["x86_64", "arm64"]' runtime: provided.al2

Invoke a Lambda function

Use the cloudbees-io/lambda-invoke-function action to invoke an existing function in AWS Lambda.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 7. Input details
Input name Data type Required? Description

function-name

String

Yes

The AWS Lambda function name.

parameters

JSON

No

The input to provide to your Lambda function, formatted as JSON data in key/value pairs.

Usage example

In your YAML file, add:

- name: Invoke AWS lambda function id: invokeLambdaFunction uses: https://github.com/cloudbees-io/lambda-invoke-function@v1 with: function-name: my-function