-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sage-monorepo): create project template for developing AWS Lambd…
…a node.js 20.x (ARCH-351) (#2932)
- Loading branch information
1 parent
56262b4
commit e391dc8
Showing
17 changed files
with
534 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/* |
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,10 @@ | ||
FROM public.ecr.aws/lambda/nodejs:20 | ||
|
||
COPY app.mjs package*.json ${LAMBDA_TASK_ROOT}/ | ||
|
||
RUN npm install | ||
# If you are building your code for production, instead include a package-lock.json file on this directory and use: | ||
# RUN npm ci --production | ||
|
||
# Command can be overwritten by providing a different command in the template directly. | ||
CMD ["app.lambdaHandler"] |
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,45 @@ | ||
# Sandbox Lambda Node.js | ||
|
||
## Build the project | ||
|
||
```console | ||
nx build sandbox-lambda-nodejs | ||
``` | ||
|
||
## Build the Docker image of the Lambda function | ||
|
||
```console | ||
nx build-image sandbox-lambda-nodejs | ||
``` | ||
|
||
## Start the Lambda function locally with Docker Compose | ||
|
||
Starts the Lambda function in the foreground, allowing you to view logs and interact with it | ||
directly. | ||
|
||
```console | ||
nx serve sandbox-lambda-nodejs | ||
``` | ||
|
||
Starts the Lambda function in detached mode, running it in the background. This is useful if you | ||
want to continue using the terminal for other tasks while the function runs. | ||
|
||
```console | ||
nx serve-detach sandbox-lambda-nodejs | ||
``` | ||
|
||
## Invoke the Lambda function locally | ||
|
||
To invoke the Lambda function after starting it locally, use the following command: | ||
|
||
```console | ||
nx run sandbox-lambda-nodejs:invoke --event <path-to-json-file> | ||
``` | ||
|
||
Replace `<path-to-json-file>` with the path to your JSON file containing the event payload relative | ||
to the location of the project folder. For example, if your event payload is stored in a file | ||
located at `events/event.json` relative to the project folder: | ||
|
||
```console | ||
nx run sandbox-lambda-nodejs:invoke --event events/event.json | ||
``` |
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,23 @@ | ||
/** | ||
* | ||
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format | ||
* @param {Object} event - API Gateway Lambda Proxy Input Format | ||
* | ||
* Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html | ||
* @param {Object} context | ||
* | ||
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html | ||
* @returns {Object} object - API Gateway Lambda Proxy Output Format | ||
* | ||
*/ | ||
|
||
export const lambdaHandler = async (event, context) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: 'hello world', | ||
}), | ||
}; | ||
|
||
return response; | ||
}; |
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,62 @@ | ||
{ | ||
"body": "{\"message\": \"hello world 2\"}", | ||
"resource": "/{proxy+}", | ||
"path": "/path/to/resource", | ||
"httpMethod": "POST", | ||
"isBase64Encoded": false, | ||
"queryStringParameters": { | ||
"foo": "bar" | ||
}, | ||
"pathParameters": { | ||
"proxy": "/path/to/resource" | ||
}, | ||
"stageVariables": { | ||
"baz": "qux" | ||
}, | ||
"headers": { | ||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | ||
"Accept-Encoding": "gzip, deflate, sdch", | ||
"Accept-Language": "en-US,en;q=0.8", | ||
"Cache-Control": "max-age=0", | ||
"CloudFront-Forwarded-Proto": "https", | ||
"CloudFront-Is-Desktop-Viewer": "true", | ||
"CloudFront-Is-Mobile-Viewer": "false", | ||
"CloudFront-Is-SmartTV-Viewer": "false", | ||
"CloudFront-Is-Tablet-Viewer": "false", | ||
"CloudFront-Viewer-Country": "US", | ||
"Host": "1234567890.execute-api.us-east-1.amazonaws.com", | ||
"Upgrade-Insecure-Requests": "1", | ||
"User-Agent": "Custom User Agent String", | ||
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", | ||
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", | ||
"X-Forwarded-For": "127.0.0.1, 127.0.0.2", | ||
"X-Forwarded-Port": "443", | ||
"X-Forwarded-Proto": "https" | ||
}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"resourceId": "123456", | ||
"stage": "prod", | ||
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", | ||
"requestTime": "09/Apr/2015:12:34:56 +0000", | ||
"requestTimeEpoch": 1428582896000, | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": null, | ||
"cognitoIdentityId": null, | ||
"caller": null, | ||
"accessKey": null, | ||
"sourceIp": "127.0.0.1", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": null, | ||
"userAgent": "Custom User Agent String", | ||
"user": null | ||
}, | ||
"path": "/prod/path/to/resource", | ||
"resourcePath": "/{proxy+}", | ||
"httpMethod": "POST", | ||
"apiId": "1234567890", | ||
"protocol": "HTTP/1.1" | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"name": "hello_world", | ||
"version": "1.0.0", | ||
"description": "hello world sample for NodeJS", | ||
"main": "app.js", | ||
"repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs", | ||
"author": "SAM CLI", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": ">=1.6.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.3.6", | ||
"mocha": "^10.2.0" | ||
} | ||
} |
Oops, something went wrong.