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

SAM Local Layers not included when intrinsic functions are used #833

Closed
martysweet opened this issue Dec 5, 2018 · 1 comment
Closed

Comments

@martysweet
Copy link

Description:
A list of layers are not used if !Sub is used (or possibly any other intrinsic function) when using the local invoke or start-api functionality. No error is thrown to alert the user than intrinsic functions may not be supported.

Steps to reproduce the issue:

  1. Create template, an example from https://github.com/stackery/php-lambda-layer
AWSTemplateFormatVersion: 2010-09-09
Description: My PHP Application
Transform: AWS::Serverless-2016-10-31
Resources:
  phpserver:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub ${AWS::StackName}-phpserver
      Description: PHP Webserver
      CodeUri: src/php
      Runtime: provided
      Handler: index.php
      MemorySize: 3008
      Timeout: 30
      Tracing: Active
      Layers:
        - !Sub arn:aws:lambda:${AWS::Region}:887080169480:layer:php71:5
      Events:
        api:
          Type: Api
          Properties:
            Path: /{proxy+}
            Method: ANY
  1. Invoke the function with sam local invoke phpserver --no-event
  2. Get error message

Observed result:
As the layer was not included, the bootstrap file is not present.

{
  "errorType": "Runtime.ExitError",
  "errorMessage": "RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"
}

Expected result:
The layer is included and the function invokes as expected.

Workaround:
Define a string for each element of the Layers array, for example:

  Layers:
        - arn:aws:lambda:eu-west-1:887080169480:layer:php71:5

This then works as expected.

Output of sam --version:
0.8.1 and tested on develop branch

Optional Debug logs:

Add --debug flag to command you are running

Broken example (using !Sub)

2018-12-05 19:56:28 Max number of attempts exceeded (1) when attempting to retrieve data from metadata service.
2018-12-05 19:56:28 Resolving code path. Cwd=/srv/development/abcd, CodeUri=src/php
2018-12-05 19:56:28 Resolved absolute path to code is /srv/development/abcd/src/php
2018-12-05 19:56:28 Code /srv/development/abcd/src/php is not a zip/jar file
2018-12-05 19:56:28 Skipping building an image since no layers were defined

Working example (using a strict String)

2018-12-05 19:57:50 Resolving code path. Cwd=/srv/development/abcd, CodeUri=src/php
2018-12-05 19:57:50 Resolved absolute path to code is /srv/development/abcd/src/php
2018-12-05 19:57:50 Code /srv/development/abcd/src/php is not a zip/jar file
2018-12-05 19:57:50 Event before-parameter-build.lambda.GetLayerVersion: calling handler <function generate_idempotent_uuid at 0x7f2a7a4856e0>
2018-12-05 19:57:50 Making request for OperationModel(name=GetLayerVersion) with params: {'body': '', 'url': u'https://lambda.eu-west-1.amazonaws.com/2018-10-31/layers/arn%3Aaws%3Alambda%3Aeu-west-1%3A887080169480%3Alayer%3Aphp71/versions/4', 'headers': {'User-Agent': 'Boto3/1.9.57 Python/2.7.12 Linux/4.4.0-122-generic Botocore/1.12.59'}, 'context': {'auth_type': None, 'client_region': 'eu-west-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7f2a75ea05d0>}, 'query_string': {}, 'url_path': u'/2018-10-31/layers/arn%3Aaws%3Alambda%3Aeu-west-1%3A887080169480%3Alayer%3Aphp71/versions/4', 'method': u'GET'}

I've seen #573, I assume this is related. Hopefully this issue will help someone from wasting a few hours on the same thing 👍

@jfuss
Copy link
Contributor

jfuss commented Dec 5, 2018

Duplicate of #813 and #528

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants