Skip to content

Commit 03f7fcb

Browse files
committed
use Node.js 18
1 parent 38e9014 commit 03f7fcb

File tree

15 files changed

+48
-24
lines changed

15 files changed

+48
-24
lines changed

sample-apps/blank-nodejs/2-build-layer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
set -eo pipefail
33
mkdir -p lib/nodejs
44
rm -rf node_modules lib/nodejs/node_modules
5-
npm install --production
5+
npm install --omit=dev
66
mv node_modules lib/nodejs/

sample-apps/blank-nodejs/4-invoke.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eo pipefail
33
FUNCTION=$(aws cloudformation describe-stack-resource --stack-name blank-nodejs --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text)
44
55
while true; do
6-
aws lambda invoke --function-name $FUNCTION --payload file://event.json out.json
6+
aws lambda invoke --function-name $FUNCTION --payload fileb://event.json out.json
77
cat out.json
88
echo ""
99
sleep 2

sample-apps/blank-nodejs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Variants of this sample application are available for the following languages:
2121
Use the following instructions to deploy the sample application. For an in-depth look at its architecture and features, see [Blank Function Sample Application for AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/samples-blank-nodejs.html) in the developer guide.
2222

2323
# Requirements
24-
- [Node.js 10 with npm](https://nodejs.org/en/download/releases/)
24+
- [Node.js 18 with npm](https://nodejs.org/en/download/releases/)
2525
- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash.
2626
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
2727

sample-apps/blank-nodejs/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"version": "1.0.0",
44
"private": true,
55
"devDependencies": {
6-
"aws-sdk": "2.814.0",
7-
"jest": "25.4.0"
6+
"jest": "29.7.0"
87
},
98
"dependencies": {
10-
"aws-xray-sdk-core": "1.1.2"
9+
"aws-sdk": "2.1484.0",
10+
"aws-xray-sdk-core": "3.5.3"
1111
},
1212
"scripts": {
1313
"test": "jest"
1414
}
15-
}
15+
}

sample-apps/blank-nodejs/template.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Resources:
66
Type: AWS::Serverless::Function
77
Properties:
88
Handler: index.handler
9-
Runtime: nodejs16.x
9+
Runtime: nodejs18.x
1010
CodeUri: function/.
1111
Description: Call the AWS Lambda API
1212
Timeout: 10
@@ -25,4 +25,4 @@ Resources:
2525
Description: Dependencies for the blank sample app.
2626
ContentUri: lib/.
2727
CompatibleRuntimes:
28-
- nodejs16.x
28+
- nodejs18.x
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$ ./4-invoke.sh
2+
{
3+
"StatusCode": 200,
4+
"ExecutedVersion": "$LATEST"
5+
}
6+
{"writeTimeMs":60.659086,"readTimeMs":"Read error: Error: ENOENT: no such file or directory, open '/mnt/efs0/test.bin'","fileSizeBytes":0}
7+
{
8+
"StatusCode": 200,
9+
"ExecutedVersion": "$LATEST"
10+
}
11+
{"writeTimeMs":60.002857,"readTimeMs":79.54446,"fileSizeBytes":1398104}
12+
{
13+
"StatusCode": 200,
14+
"ExecutedVersion": "$LATEST"
15+
}
16+
{"writeTimeMs":50.76445,"readTimeMs":39.566218,"fileSizeBytes":1398104}
17+
{
18+
"StatusCode": 200,
19+
"ExecutedVersion": "$LATEST"
20+
}
21+
{"writeTimeMs":60.457508,"readTimeMs":199.181445,"fileSizeBytes":1398104}
22+
{
23+
"StatusCode": 200,
24+
"ExecutedVersion": "$LATEST"
25+
}

sample-apps/efs-nodejs/3-deploy.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ if [[ $# -eq 1 ]] ; then
66
STACK=$1
77
echo "Deploying to stack $STACK"
88
fi
9-
cd lib/nodejs && npm install && cd ../../
109
aws cloudformation package --template-file template.yml --s3-bucket $ARTIFACT_BUCKET --output-template-file out.yml
1110
aws cloudformation deploy --template-file out.yml --stack-name $STACK --capabilities CAPABILITY_NAMED_IAM
1211

sample-apps/efs-nodejs/4-invoke.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eo pipefail
33
FUNCTION=$(aws cloudformation describe-stack-resource --stack-name efs-nodejs --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text)
44
55
while true; do
6-
aws lambda invoke --function-name $FUNCTION --payload file://event.json out.json
6+
aws lambda invoke --function-name $FUNCTION --payload fileb://event.json out.json
77
cat out.json
88
echo ""
99
sleep 2

sample-apps/efs-nodejs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Use the following instructions to deploy the sample application.
2828

2929
To deploy the sample application, you need the following tools:
3030

31-
- [Node.js 10 with npm](https://nodejs.org/en/download/releases/).
31+
- [Node.js 18 with npm](https://nodejs.org/en/download/releases/).
3232
- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash.
3333
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
3434

sample-apps/efs-nodejs/function/index.js renamed to sample-apps/efs-nodejs/function/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var fs = require('fs').promises
2-
const crypto = require('crypto')
1+
import fs from 'node:fs/promises'
2+
const crypto = await import('node:crypto')
33
const dir = process.env.mountPath
44

5-
exports.handler = async function(event) {
5+
export const handler = async (event) => {
66
console.log("EVENT: %s", JSON.stringify(event, null, 2))
77
const filePath = dir + "/" + event.fileName
88
const fileSize = event.fileSize
99
// generate file
10-
const buffer = await crypto.randomBytes(fileSize)
10+
const buffer = crypto.randomBytes(fileSize)
1111
// write operation
1212
const writeTimeMs = await writeFile(filePath, buffer)
1313
// read file

sample-apps/efs-nodejs/template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Resources:
2525
mountPath: !Ref mountPath
2626
MemorySize: 128
2727
Timeout: 15
28-
Runtime: nodejs12.x
28+
Runtime: nodejs18.x
2929
Tracing: Active
3030
Handler: index.handler
3131
VpcConfig:

sample-apps/nodejs-apig/3-invoke.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eo pipefail
33
FUNCTION=$(aws cloudformation describe-stack-resource --stack-name nodejs-apig --logical-resource-id function --query 'StackResourceDetail.PhysicalResourceId' --output text)
44
55
while true; do
6-
aws lambda invoke --function-name $FUNCTION --payload file://event.json out.json
6+
aws lambda invoke --function-name $FUNCTION --payload fileb://event.json out.json
77
cat out.json
88
echo ""
99
sleep 2

sample-apps/nodejs-apig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The project source includes function code and supporting resources:
1515
Use the following instructions to deploy the sample application.
1616

1717
# Requirements
18-
- [Node.js 10 with npm](https://nodejs.org/en/download/releases/)
18+
- [Node.js 18 with npm](https://nodejs.org/en/download/releases/)
1919
- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash.
2020
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
2121

sample-apps/nodejs-apig/function/index.js renamed to sample-apps/nodejs-apig/function/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
const AWS = require('aws-sdk')
1+
import {LambdaClient, GetAccountSettingsCommand} from '@aws-sdk/client-lambda';
22
// Create client outside of handler to reuse
3-
const lambda = new AWS.Lambda()
3+
const lambda = new LambdaClient()
44

55
// Handler
6-
exports.handler = async function(event, context) {
6+
export const handler = async (event, context) => {
77
console.log('## ENVIRONMENT VARIABLES: ' + serialize(process.env))
88
console.log('## CONTEXT: ' + serialize(context))
99
console.log('## EVENT: ' + serialize(event))
1010
try {
11-
let accountSettings = await getAccountSettings()
11+
let accountSettings = await lambda.send(new GetAccountSettingsCommand())
1212
return formatResponse(serialize(accountSettings.AccountUsage))
1313
} catch(error) {
1414
return formatError(error)

sample-apps/nodejs-apig/template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Resources:
1212
Type: AWS::Serverless::Function
1313
Properties:
1414
Handler: index.handler
15-
Runtime: nodejs12.x
15+
Runtime: nodejs18.x
1616
CodeUri: function/.
1717
Description: Call the AWS Lambda API
1818
Timeout: 10

0 commit comments

Comments
 (0)