Skip to content

sam local invoke fails with AccessDeniedException when working with Layers #1736

Open
@kulkaamb

Description

@kulkaamb

Description:

When you use sam local invoke on a Lambda having layers, it fails with

Error: Credentials provided are missing lambda:Getlayerversion policy that is needed to download the layer or you do not have permission to download the layer

The --profile used to run the command had access lambda:* access but sam still fails with this error. Access is verified with aws commandline.

Steps to reproduce the issue:

  1. Declare a template with Layers, something like
    Layers:
    - !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:XRayLayer:${XRayLayerVersion}"
  2. When Lambda is locally invoked for testing :
    sam local invoke -e .\test-data\test-sqs-event.json myservice --profile default --debug --region us-east-1
    function invocation fails with

Error: Credentials provided are missing lambda:Getlayerversion policy that is needed to download the layer or you do not have permission to download the layer
3. Running the function in debug mode does not help, it does not reveal any additional details.
4. Running the function with start-lambda in debug mode and invoking the lambda with aws cli gives more insights, and there is a bug

sam local start-lambda --profile default --debug --region us-east-1

GetLayer call in the background is making call to a dummy account 123456789012 and not the actual account you are working with : log shows something like this

botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the GetLayerVersion operation: User: arn:aws:sts::[account]:assumed-role/[Role]/user is not authorized to perform: lambda:GetLayerVersion on resource: arn:aws:lambda:us-east-1:123456789012:layer:XRayLayer:6 and that's the bug
it should be using the account from aws --profile

See attached log for both sam local start-lambda and local invoke giving details.

sam bugreport.txt

Observed result:
AccessDeniedException

Expected result:
sam is supposed to download the layer specified in the sam template.

Workaround:
if you hardcode the account in layer ARN in template, it downloads the layer and then subsequent runs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions