eugene-manuilov / cfpack

A CLI tool that helps to build CloudFormation template using multiple smaller templates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support uploading of local artifacts

jonlorusso opened this issue · comments

It is possible to upload local artifacts to s3 prior to a deploy using the aws cli package command.

Currently when I use cfpack on a template that makes use of this mechanism I get the following error(s):

[19:59:18] cfpacktest CREATE_IN_PROGRESS Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [CognitoCustomMessageLambda] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter. Resource with id [CreateProfileLambda] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter. Resource with id [FetchQueryResultSingleAuthenticatedLambda] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter. Resource with id [SendTemplatedEmailLambda] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter. Resource with id [SystemInformationLambda] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter.

cfpack would need to somehow invoke the package command (or equivalent) during its build stage.

Edit: Looking into the source code of the aws-cli program, package is just a python script that uploads local artifacts to s3 and then modifies the input template. The only options appear to be invoking this command from cfpack or reimplementing it within cfpack. 😢

Hi @jonlorusso

could you please show me your template? cfpack uses AWS Node.js API, so I am sure that it is possible to upload something to a s3 bucket. Just want to see your template as an example of a use case.

@eugene-manuilov

So here's a snippet:

  AppSyncSchema:
    Type: "AWS::AppSync::GraphQLSchema"
    Properties:
      DefinitionS3Location: schema.graphql
      ApiId: !GetAtt [ AppSyncAPI, ApiId ]

When I run the aws cloudformation package command, the schema.graphql file is uploaded to S3 and the template is modified:

    Properties:
      ApiId:
        Fn::GetAtt:
        - AppSyncAPI
        - ApiId
      DefinitionS3Location: s3://mystackname/db7c9d50e4e8e71d3653438745db5fd8

Thanks @jonlorusso. I am going to add artifacts section to the cfpack.config.js file where you will be able to define files that need to be uploaded before deploy. It will look like this:

module.exports = {
    entry: "...",
    output: "...",
    verbose: true,
    silent: false,
    stack: {
        name: "...",
        region: "...",
        params: {
            ...
        },
        artifacts: [
            {
                bucket: 'my-bucket',
                files: {
                    'api/schema.graphql': 'local/schema/schema.graphql',
                    'lambdas/first-function.zip': {
                        include: ['*.js', '*.json'],
                        exclude: ['package-lock.json', 'tests/**/*'],
                        path: 'local/files/**/*',
                        compression: 'zip', // zip | tar.gz | none
                    },
                },
            },
        ],
    },
};

Then you will need to update your snippet to be:

  AppSyncSchema:
    Type: "AWS::AppSync::GraphQLSchema"
    Properties:
      DefinitionS3Location: s3://my-bucket/api/schema.graphql
      ApiId: !GetAtt [ AppSyncAPI, ApiId ]

Then when you run cfpack deploy command, it will prepare artifacts and upload it to s3 bucket first, then will trigger CloudFormation stack update. Does it make sense to you?

Hi @jonlorusso

the new version has been just published. It contains functionality that allows to upload artifacts before updating CloudFormation stack. Please, let me know if it help.

https://github.com/eugene-manuilov/cfpack#artifacts-1

Closing this task now. Feel free to open a new one if you have anything else.