Skip to content

Commit d6a5439

Browse files
authored
AWS SDK V3: Migrate CreateFunction to v3 (#757)
GH-641 This is still an experimental migration. First, only CreateFunction will be migrated. We also plan to maintain unit tests.
1 parent 5e46ee2 commit d6a5439

File tree

4 files changed

+8899
-4728
lines changed

4 files changed

+8899
-4728
lines changed

lib/main.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const CloudWatchLogs = require(path.join(__dirname, 'cloudwatch_logs'))
1919
const AWSXRay = require('aws-xray-sdk-core')
2020
const { createNamespace } = require('continuation-local-storage')
2121

22+
// Migrating to v3.
23+
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda')
24+
const lambdaClient = new LambdaClient()
25+
2226
const maxBufferSize = 50 * 1024 * 1024
2327

2428
class Lambda {
@@ -236,8 +240,8 @@ Emulate only the body of the API Gateway event.
236240
Role: program.role,
237241
Runtime: program.runtime,
238242
Description: program.description,
239-
MemorySize: program.memorySize,
240-
Timeout: program.timeout,
243+
MemorySize: Number(program.memorySize),
244+
Timeout: Number(program.timeout),
241245
Architectures: program.architecture ? [program.architecture] : ['x86_64'],
242246
Publish: (() => {
243247
if (typeof program.publish === 'boolean') {
@@ -688,6 +692,13 @@ Emulate only the body of the API Gateway event.
688692
}
689693

690694
_uploadNew (lambda, params) {
695+
if (process.env.USE_AWS_SDK_V3) {
696+
// todo retry
697+
console.log('DEBUG: Use AWS SDK V3: CreateFunctionCommand()')
698+
const command = new CreateFunctionCommand(params)
699+
return lambdaClient.send(command)
700+
}
701+
691702
return new Promise((resolve, reject) => {
692703
const request = lambda.createFunction(params, (err, data) => {
693704
if (err) return reject(err)

0 commit comments

Comments
 (0)