Skip to content

Commit

Permalink
feat(lambda): allow running a build file (#30196)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes #18470

### Reason for this change

This allows customers to execute an arbitrary build script as part of cdk synth, which will enable customer to use esbuild plugins. The rationale for this decision is given the issue that is linked above.

### Description of changes

1. Expose the code field on the `aws-lambda-nodejs` construct, so that customers can specify code in ways other than bundling, which was the default and abstracted away from customers before this change.
2. Add a new static method on Code, namely `Code.fromCustomCommand`. This method takes in the commands to run an arbitrary script during cdk synthesis that the customer provides. The customer also provides the location of the output from the buildscript. Then this output is supplied to a lambda function.

### Description of how you validated changes

manual testing (involving inspecting output in the AWS Lambda console and invoking the function), integration tests, and full unit test coverage of new changes.

### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bergjaak committed May 30, 2024
1 parent 948e6d5 commit 89042c4
Show file tree
Hide file tree
Showing 22 changed files with 32,928 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail

directoryOfThisScript=$(cd $(dirname $0) && pwd)
echo "directoryOfThisScript: $directoryOfThisScript"
cp "$directoryOfThisScript/custom_command_handler.js" "$directoryOfThisScript/../custom_command_output/mylambdafile.js"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function handler() {
return 'NICE';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code gets placed in here from the integ.specifycode.ts test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 89042c4

Please sign in to comment.