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

Local CDK Lambda Layer asset path not respected #1411

Closed
abrooksv opened this issue Sep 13, 2019 · 3 comments · Fixed by aws/aws-cdk#4205
Closed

Local CDK Lambda Layer asset path not respected #1411

abrooksv opened this issue Sep 13, 2019 · 3 comments · Fixed by aws/aws-cdk#4205

Comments

@abrooksv
Copy link
Contributor

abrooksv commented Sep 13, 2019

Description

When using CDK to create a layer, SAM local does not respect the aws:asset:path metadata.

Steps to reproduce

Generated template snippet:

      "Type": "AWS::Lambda::LayerVersion",
      "Properties": {
        "Content": {
          "S3Bucket": {
            "Ref": "LayerCodeS3Bucket01B5996C"
          },
          "S3Key": {
            "Fn::Join": [
              "",
              [
                {
                  "Fn::Select": [
                    0,
                    {
                      "Fn::Split": [
                        "||",
                        {
                          "Ref": "LayerCodeS3VersionKey1E2A5824"
                        }
                      ]
                    }
                  ]
                },
                {
                  "Fn::Select": [
                    1,
                    {
                      "Fn::Split": [
                        "||",
                        {
                          "Ref": "LayerCodeS3VersionKey1E2A5824"
                        }
                      ]
                    }
                  ]
                }
              ]
            ]
          }
        }
      },
      "Metadata": {
        "aws:cdk:path": "Stack/Layer/Resource",
        "aws:asset:path": "/tmp/aws-lambda-layer-kubectl/layer.zip",
        "aws:asset:property": "Code"
      }
    },

Modified lambda_downloader.py to add logging:

        if layer.is_defined_within_template:
            LOG.info("%s is a local Layer in the template", layer.name)
            LOG.info("HELLO %s", layer.codeuri)
            layer.codeuri = resolve_code_path(self.cwd, layer.codeuri)
            LOG.info("FUN %s", layer.codeuri)
            return layer

Observed result

Logs:

[sam] Layer129049A2 is a local Layer in the template
[sam] HELLO .
[sam] FUN /Users/..../dist/cdk
[sam] Image was not found.
[sam] Building image...

Expected result

HELLO should say /tmp/aws-lambda-layer-kubectl/layer.zip

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

  1. OS: OS X
  2. sam --version: 0.21.0

Add --debug flag to command you are running

@jfuss
Copy link
Contributor

jfuss commented Sep 13, 2019

@abrooksv Looks like a CDK bug. A Layer does not have a property 'Code', it should be 'Content'. LayerVersion docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html

@abrooksv
Copy link
Contributor Author

Overwrote the template:

      "Metadata": {
        "aws:cdk:path": "Stack/Layer/Resource",
        "aws:asset:path": "/tmp/aws-lambda-layer-kubectl/layer.zip",
        "aws:asset:property": "Content"
      }

Leads to:

HELLO /tmp/aws-lambda-layer-kubectl/layer.zip
Resolving code path. Cwd=/Users/.../dist/cdk, CodeUri=/tmp/aws-lambda-layer-kubectl/layer.zip
FUN /tmp/aws-lambda-layer-kubectl/layer.zip

@jfuss
Copy link
Contributor

jfuss commented Sep 16, 2019

CDK has the 'aws:asset:property` set incorrectly.

As far as the second issue (not allowing zip), we have an open issue for that here #947 but really the path should be pointed to the source (none-zipped asset).

Closing as an issue is open with CDK and we already have an tracking issue for the other issue brought up.

@jfuss jfuss closed this as completed Sep 16, 2019
eladb pushed a commit to aws/aws-cdk that referenced this issue Sep 23, 2019
The `aws:asset:property` metadata entry was "Code" intead of "Content" as it should be for lambda layers.

Fixes #4076
Fixes aws/aws-sam-cli#1411
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Sep 23, 2019
* fix(lambda): asset metadata invalid for layers

The `aws:asset:property` metadata entry was "Code" intead of "Content" as it should be for lambda layers.

Fixes #4076
Fixes aws/aws-sam-cli#1411

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

Successfully merging a pull request may close this issue.

2 participants