-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): aws.Function.context() for lambda functions (#6424)
Closes #6412 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
14 changed files
with
426 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./assert"; | ||
export * from "./expect"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as cloud from "../cloud"; | ||
|
||
export function makeAwsLambdaHandler( | ||
handler: cloud.IFunctionHandler | ||
): string[] { | ||
const inflightClient = handler._toInflight(); | ||
const lines = new Array<string>(); | ||
const client = "$handler"; | ||
|
||
lines.push('"use strict";'); | ||
lines.push(`var ${client} = undefined;`); | ||
lines.push("exports.handler = async function(event, context) {"); | ||
lines.push(" try {"); | ||
lines.push(" if (globalThis.$awsLambdaContext === undefined) {"); | ||
lines.push(" globalThis.$awsLambdaContext = context;"); | ||
lines.push(` ${client} = ${client} ?? (${inflightClient});`); | ||
lines.push(" } else {"); | ||
lines.push(" throw new Error("); | ||
lines.push(" 'An AWS Lambda context object was already defined.'"); | ||
lines.push(" );"); | ||
lines.push(" }"); | ||
|
||
// important: we're calling handle() within a try block, but there's no catch block | ||
// because we want to let the error propagate to the AWS Lambda runtime | ||
lines.push( | ||
` return await ${client}.handle(event === null ? undefined : event);` | ||
); | ||
lines.push(" } finally {"); | ||
lines.push(" globalThis.$awsLambdaContext = undefined;"); | ||
lines.push(" }"); | ||
lines.push("};"); | ||
|
||
return lines; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.