Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS cli create deployment without appspec file

Is there a way to run AWS Codedeploy without the use of an appspec.yml file?

I am looking for a way to create a 100% purely command line way of running create-deployment without the use of any yml files in S3 bucket

like image 438
Moses Liao GZ Avatar asked Apr 24 '26 13:04

Moses Liao GZ


2 Answers

I found examples with YAML input but not with JSON input online. While YAML has its advantages, sometimes JSON is easier to work with in my opinion (in bash/gitlab CI scripts for example).

The way to call aws deploy using JSON without the use of S3 and constructing the Appspec content in a variable:

APPSPEC=$(echo '{"version":1,"Resources":[{"TargetService":{"Type":"AWS::ECS::Service","Properties":{"TaskDefinition":"'${AWS_TASK_DEFINITION_ARN}'","LoadBalancerInfo":{"ContainerName":"react-web","ContainerPort":3000}}}}]}' | jq -Rs .)

Note the jq -Rs . at the end: the content should be a JSON-as-String and not be part of the actual JSON. Using jq we escape the JSON. Replace the variables as needed (AWS_TASK_DEFINITION_ARN, ContainerName and ContainerPort etc.)

REVISION='{"revisionType":"AppSpecContent","appSpecContent":{"content":'${APPSPEC}'}}'

And finally we can create the deployment with the new revision:

aws deploy create-deployment --application-name "${AWS_APPLICATION_NAME}" --deployment-group-name "${AWS_DEPLOYMENT_GROUP_NAME}" --revision "$REVISION"

Tested on aws-cli/2.4.15

like image 183
Matthijs Avatar answered Apr 27 '26 06:04

Matthijs


It's possible to create a deployment without appspec.yaml files in S3 for AWS Lambda/ECS deployments.

With AWS Cli V2: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/deploy/create-deployment.html

aws deploy create-deployment --cli-input-yaml file://code-deploy.yaml

Where code-deploy.yaml would have the following structure (example for ecs service):

applicationName: 'code-deploy-app'
deploymentGroupName: 'code-deploy-deployment-group'
revision:
  revisionType: AppSpecContent
  appSpecContent:
    content: |
      version: 0.0
      Resources:
        - TargetService:
            Type: AWS::ECS::Service
            Properties:
              TaskDefinition: "[YOUR_TASK_DEFINITION_ARN]"
              LoadBalancerInfo:
                ContainerName: "ecs-service-container"
                ContainerPort: 8080
like image 44
Miguel Santos Avatar answered Apr 27 '26 04:04

Miguel Santos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!