chore(layers): bundle assets from source when testing #1710
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR introduces some changes to the way the Lambda Layers are built when running integration tests. The changes should be backward compatible with the current release process, which should work as before for the most part.
Below a matrix of the changes and the areas they are supposed to impact:
Bundling Script
Before this PR we had a bash script present in the
.github/scripts/
folder that had to be run before deploying the layers or running tests.This was fine in the CI environment since it was only an additional step. When working locally however we didn't have any automated way of running it and contributors/maintainers had to remember to run it before being able to run the integration tests for the
layers
workspace.This PR removes this script in favor of using CDK local bundling. The
Code.fromAsset()
method that we use to reference the layer content accepts two arguments: the location of the asset and a bundling configuration object.Even though this is not really well documented, it's possible to force the bundling to happen locally and without Docker. This is exactly what the
NodejsFunction
L3 construct does under the hood and also what described here in passing.The command looks something like this, but with more
execSync
commands:With this method we don't have to maintain two scripts and the build process is always run automatically as part of the synth process 🚀 .
Lambda Function
Before this release we were performing the following checks:
package.json
file of one utility (Logger) matches the expected versionColdStart
)This PR changes the first and last actions to:
package.json
files of each utility present in the layer matches the expected oneThe first one is mainly for an excess of caution, however the second was needed because most of the methods in the Tracer are treated as non-critical and as such they are not meant to throw if they don't succeed. By logging the content of a segment we can test that the actions we perform actually happened.
Build Steps
As mentioned in the linked issue, before this PR we didn't have any means to test the Powertools utilities in a Layer without making a release. This PR introduces a new CDK context variable called
BuildFromSource
that allows to tell the CDK construct to build the packages from sources before deploying the Lambda Layer (defaults tofalse
).This behavior is set to
true
in the integration tests but defaults tofalse
in the release pipeline. WhenBuildFromSource
istrue
, the build process runsnpm run build -w packages/<utility>
andnpm pack -w packages/<utility>
, then uses the resulting tarballs to install the utility in the layer folder.This not only allows us to test the code we are working on in the integration tests, but also serves as an early canary for the build/pack process itself.
Related issues, RFCs
Issue number: closes #1709
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.