Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::Serverless::LayerVersion does not respect a single String Parameter for CompatibleRuntimes #809

Closed
systemdesignpartners opened this issue Feb 12, 2019 · 3 comments
Assignees
Labels
contributors/good-first-issue Good first issue for a contributor type/bug

Comments

@systemdesignpartners
Copy link

Description

In a template.yaml specifying AWS::Serverless::LayerVersion, unable to specify a single !Ref ParameterName to CompatibleRuntimes, even if you try to send it as a List (of one item)

template.yaml snippet

Parameters:
MyLambdaRuntimeParam:
Type: String
Default: 'nodejs8.10'

Layer1:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: layer-1
ContentUri:
Bucket: ...
Key: ...
CompatibleRuntimes:
- !Ref MyLambdaRuntimeParam

(You can also try it without a dash in front of !Ref, or with two dashes, or with no dashes and no "!Ref" token, it still fails)

Observed result

-- Two debug runs here, for three different ways of trying it. First run has two different-syntax attempts:
Layer1:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: layer-1
Description: "Bug Example #1"
ContentUri:
Bucket: !Ref MyLambdaBucketNameParam
Key: 'lambda-zips/layer-aws-wrapper_v2_no_xray.zip'
CompatibleRuntimes:
- !Ref MyLambdaRuntimeParam

Layer2:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: layer-2
Description: "Bug Example #2"
ContentUri:
Bucket: !Ref MyLambdaBucketNameParam
Key: 'lambda-zips/layer-aws-wrapper_v2_no_xray.zip'
CompatibleRuntimes:
- - !Ref MyLambdaRuntimeParam

And --debug output when running sam deploy was:

2019-02-12 12:55:33 deploy command is called
Uploading to 84451a0ac75787cc911fcc8331083ae3.template 3288 / 3288.0 (100.00%)
Waiting for changeset to be created..

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [Layer1] is invalid. Type of property 'CompatibleRuntimes' is invalid. Resource with id [Layer2] is invalid. Type of property 'CompatibleRuntimes' is invalid.
2019-02-12 12:55:39 Exception: Command '['aws', 'cloudformation', 'deploy', '--capabilities', 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND', '--region', 'us-east-2', '--s3-bucket', 'sdp-yourpitchcount-repl-east2', '--parameter-overrides', 'MyAppPrefixParam=pitchaur', 'MyLambdaBucketNameParam=sdp-yourpitchcount-repl-east2', '--tags', 'deployed-via=p-sdepl-layers.sh', '--stack-name', 'sdp-yourpitchcount-layers', '--template-file', 'packaged-layers.yaml']' returned non-zero exit status 255.

Trying it a third way, we get a little further but still the Stack rolls back:

Layer3:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: layer-3
Description: "Bug Example #3"
ContentUri:
Bucket: !Ref MyLambdaBucketNameParam
Key: 'lambda-zips/layer-aws-wrapper_v2_no_xray.zip'
CompatibleRuntimes:
!Ref MyLambdaRuntimeParam

Throws a Create_Failed event with Status Reason:
Property validation failure: [Value of property {/CompatibleRuntimes} does not match type {Array}]
And the Stack rolls back

Expected result

Expected result was that at least one of these should have worked, and created the LayerVersion (thought that the example "Layer1" above would work)

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Ubuntu 18
  2. sam --version:
    SAM CLI, version 0.11.0
@jfuss jfuss transferred this issue from aws/aws-sam-cli Feb 12, 2019
@jfuss
Copy link
Contributor

jfuss commented Feb 12, 2019

Moving to SAM as this is about the Spec

@brettstack brettstack added type/bug contributors/good-first-issue Good first issue for a contributor labels Feb 12, 2019
@brettstack
Copy link
Contributor

Thanks for reporting this; it seems like a bug and should be a quick fix if someone wants to contribute. We need to:

  1. Update tests to include this scenario (list of intrinsic functions) https://github.com/awslabs/serverless-application-model/blob/0425efc396b659c8d0dea5b63c3287cb915d6b34/tests/translator/input/layers_with_intrinsics.yaml#L20
  2. Allow intrinsics/objects in this parameter for AWS::Lambda::LayerVersion https://github.com/awslabs/serverless-application-model/blob/0425efc396b659c8d0dea5b63c3287cb915d6b34/samtranslator/model/lambda_.py#L92
  3. Similarly, allow intrinsics/objects in this parameter for AWS::Serverless::LayerVersion https://github.com/awslabs/serverless-application-model/blob/0425efc396b659c8d0dea5b63c3287cb915d6b34/samtranslator/model/sam_resources.py#L596

You can use the Policies on Serverless::Function as an example of how to implement this https://github.com/awslabs/serverless-application-model/blob/0425efc396b659c8d0dea5b63c3287cb915d6b34/samtranslator/model/sam_resources.py#L44.

@mgrandis
Copy link
Contributor

Fixed by #1683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributors/good-first-issue Good first issue for a contributor type/bug
Projects
None yet
Development

No branches or pull requests

6 participants