Aws-cli: `CodeUri` defined in Globals section is ignored when packaging

Created on 12 Jun 2018  路  6Comments  路  Source: aws/aws-cli

When executing aws cloudformation package to upload Lambda function ZIP's to S3, the CodeUri property is not inherited from the Globals section.

The SAM documentation makes it appear that it should be possible to specify CodeUri in the Globals section and have it inherited by all AWS::Serverless::Function resources. However, because the current package implementation does not do any kind of transformation involving the globals, this is ignored and the CodeUri property appears to lack a value. The behavior in this case is to zip up the current directory which can lead to all kinds of unexpected behavior (large archives described here, Lambda errors due to incorrect relative paths, etc.).

Would it be acceptable to add something like a dict.update() in the resource export function to make sure that global values for CodeUri are inherited? I can take a whack at it and submit a pull request.

cloudformation packagdeploy customization feature-request

Most helpful comment

Submitted pull request 3391 to deal with this behavior.

All 6 comments

Okay, I wrote an implementation that combines the global and resource-level properties and it works as I expect in regards to archive creation.

The problem though is that this command also transforms the CodeUri property after it uploads the ZIP archive to S3. This means that as it iterates through the resources it would somehow have to track which are inheriting and which aren't, and finish by updating the global CodeUri property. I think this would make all of the functions in the artifact_exporter.py module a bit less agnostic.

It's looking like this would involve more than just a couple lines being added. I'm still happy to help, but I'm looking for maintainer guidance before I write a big patch that doesn't conform.

Submitted pull request 3391 to deal with this behavior.

Hi @bmoller thank you for your contribution.

@sanathkr can you please review the PR?

Hi, I would like to see this implemented. Took me a bit of time to realize this was the expected outcome of CodeUri being specified in Globals. Seems a little counter-intuitive.

Hi,
What is the status on this?
I fell for the CodeUri in globals today = Thanks

In addition to the issues @bmoller listed in the original report, if there are multiple functions that share the same CodeUri, that directory is only packaged once if it is specified directly on each resource. If it is specified in Globals, the entire current directory is uploaded once for each function defined in the template which can make the build incredibly slow if the template has multiple functions that share the same source directory.

For a Node template, uploading the entire working directory will probably also include node_modules which is almost always not desirable.

Was this page helpful?
0 / 5 - 0 ratings