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

feat(lambda-layers): add AWS SDK JS layer #5077

Closed
wants to merge 1 commit into from

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Nov 18, 2019

Add a new package @aws-cdk/lambda-layers that offers pre-built layers.

Layer building is currently only supported for Node.js and works as follows:

  • List static members of the Layer class (= layers to build)
  • Create a dummy package.json file containing only dependencies for this layer
    in the layers folder. Dependencies versions are extracted from the package.json
    of @aws-cdk/lambda-layers.
  • Run npm install

As layer dependencies are extracted from the main package.json they can be picked
up by dependabot, automatically updating the layer when needed.

The getLayerVersion() method returns a singleton lambda.LayerVersion that can be
used in Lambda functions.

The first layer is AWS_SDK_JS which offers a more recent version of the AWS SDK than
the one included in the Lambda runtime (it will also be updated more frequently).

Use the AWS_SDK_JS layer in AwsCustomResource and AwsApi event target.

Closes #2689
Closes #5063


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Add a new package `@aws-cdk/lambda-layers` that offers pre-built layers.

Layer building is currently only supported for Node.js and works as follows:
* List static members of the `Layer` class (= layers to build)
* Create a dummy `package.json` file containing only dependencies for this layer
in the `layers` folder. Dependencies versions are extracted from the `package.json`
of `@aws-cdk/lambda-layers`.
* Run `npm install`

As layer dependencies are extracted from the main `package.json` they can be picked
up by `dependabot`, automatically updating the layer when needed.

The `getLayerVersion()` method returns a singleton `lambda.LayerVersion` that can be
used in Lambda functions.

The first layer is `AWS_SDK_JS` which offers a more recent version of the AWS SDK than
the one included in the Lambda runtime (it will also be updated more frequently).

Use the `AWS_SDK_JS` layer in `AwsCustomResource` and `AwsApi` event target.

Closes aws#2689
Closes aws#5063
@jogold jogold requested a review from eladb as a code owner November 18, 2019 16:04
@mergify
Copy link
Contributor

mergify bot commented Nov 18, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@markusl
Copy link
Contributor

markusl commented Nov 19, 2019

This looks like something that would make it much easier to implement utility lambdas like the one I made for handling the ECR image scan results (https://github.com/markusl/ecr-image-scan-result-handler-lambda). I can see that after these changes, the functionality could be implemented directly as CDK Custom Resource, if I understand the PR correctly. Thanks for implementing this @jogold :)

@eladb
Copy link
Contributor

eladb commented Nov 19, 2019

@jogold, as usual, creative and interesting and definitely something I'd like to look into. Due to re:Invent coming up very soon, I am not sure I'll be able to give this the needed attention. I'll try but can't promise. It's on my radar and the direction is super interesting.

Two quick observations:

  1. I am concerned with a single module that includes many layers because the dependency graph will not look good.
  2. I am wondering if there's a way to actually publish those layers as part of our release pipeline into a public replicated S3 bucket and consume them. It's definitely much more heavy lifting from our side but it will speed up builds dramatically for people...

@jogold
Copy link
Contributor Author

jogold commented Nov 22, 2019

2. I am wondering if there's a way to actually publish those layers as part of our release pipeline into a public replicated S3 bucket and consume them.

SAR applications could be a solution, there is a similar discussion in #3797. The first step could be to develop a L2 construct for this maybe? This means that you would have a CDK app within the CDK repo

Also, I'm facing issues with the integ tests here: when a new version of the aws-sdk is released dependabot will open a PR but the source hash of the layer will change, meaning that someone will have to manually update the PR to update the integ tests where this layer is used...

@jogold
Copy link
Contributor Author

jogold commented Nov 25, 2019

Related: aws/aws-sdk-js#2528

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

5 similar comments
@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@jogold
Copy link
Contributor Author

jogold commented Dec 16, 2019

Close in favor of #5442 that tries to solve the same problem? Offering pre-built layers can still be interesting though.

@eladb
Copy link
Contributor

eladb commented Dec 16, 2019

Ok, closing for now. I agree that this is definitely an interesting area to explore.

@eladb eladb closed this Dec 16, 2019
@jogold jogold deleted the lambda-layers branch January 24, 2020 15:17
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 this pull request may close these issues.

customize the latest SDK version in custom-resource Use a lower level API of the SDK in AwsCustomResource
4 participants