Skip to content

Package addons CloudFormation templates before deployments #3546

@efekarakus

Description

@efekarakus

Ask

Allow writing templates in the addons/ directory that can refer to local artifacts (local paths).
Copilot should upload local artifacts, such as source code for an AWS Lambda function or a Swagger file for an AWS API Gateway REST API, to an S3 bucket. Following that, it should write an edited version of the template replacing references to local artifacts with the S3 location of the artifacts. Finally, this transformed template should be uploaded to the S3 bucket and used for the AddonsStack.

This functionality should be in parity with the aws cloudformation package command.
Gitter thread: https://gitter.im/aws/copilot-cli?at=627a8caaeaf3267f8553fef6

Example

Let's imagine I have the following workspace structure:

.
├── copilot/
│   └── api/
│       ├── manifest.yml
│       └── addons/
│           └── ddb.yml
└── src/
    ├── ...
    └── lambda/
        └── stream-replicator.py

In the ddb.yml template, I'd like to refer to the src/lambda/stream-replicator.py function directly in the template. Otherwise, I'd need to run aws cloudformation package --template-file copilot/api/addons/ddb.yml before copilot deploy. Instead, I want copilot to take over this burden:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  ProcessDynamoDBStream:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: /src/lambda/stream-replicator.py  # NEW
      ...

Copilot should zip the file and upload it to the environment regional S3 bucket:

ArtifactBucketARN string // ARN of the regional application bucket.

This is already where Copilot uploads pipeline, and manual deployment artifacts.

Then Copilot will transform the template such that the Serverless Function's CodeUri has the s3 URL as value.

Specification

We should have parity with the AWS CLI:

    BodyS3Location property for the AWS::ApiGateway::RestApi resource
    Code property for the AWS::Lambda::Function resource
    CodeUri property for the AWS::Serverless::Function resource
    DefinitionS3Location property for the AWS::AppSync::GraphQLSchema resource
    RequestMappingTemplateS3Location property for the AWS::AppSync::Resolver resource
    ResponseMappingTemplateS3Location property for the AWS::AppSync::Resolver resource
    DefinitionUri property for the AWS::Serverless::Api resource
    Location parameter for the AWS::Include transform
    SourceBundle property for the AWS::ElasticBeanstalk::ApplicationVersion resource
    TemplateURL property for the AWS::CloudFormation::Stack resource
    Command.ScriptLocation property for the AWS::Glue::Job resource
    DefinitionS3Location property for the AWS::StepFunctions::StateMachine resource

https://docs.aws.amazon.com/cli/latest/reference/cloudformation/package.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/addonIssues about addons.size/MWe should be able to deliver roughly 1 medium issue in a sprint.type/featureIssues that are new feature requests.type/requestIssues that are created by customers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions