AWS cli create deployment without appspec file

Viewed 452

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

3 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

Unfortunately there is no way to perform CodeDeploy without the use of an appsepc file.

You can use CodePipeline to deploy your assets to an S3 bucket (which does not require an appspec). But if they're then going down to an EC2 instance you would need to find your own way to have them be pulled down.

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
Related