Skip to content

Commit

Permalink
AWS SDK V3: Migrate CreateFunction to v3 (#757)
Browse files Browse the repository at this point in the history
GH-641

This is still an experimental migration.
First, only CreateFunction will be migrated.
We also plan to maintain unit tests.
abetomo authored Oct 17, 2024
1 parent 5e46ee2 commit d6a5439
Showing 4 changed files with 8,899 additions and 4,728 deletions.
15 changes: 13 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ const CloudWatchLogs = require(path.join(__dirname, 'cloudwatch_logs'))
const AWSXRay = require('aws-xray-sdk-core')
const { createNamespace } = require('continuation-local-storage')

// Migrating to v3.
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda')
const lambdaClient = new LambdaClient()

const maxBufferSize = 50 * 1024 * 1024

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

_uploadNew (lambda, params) {
if (process.env.USE_AWS_SDK_V3) {
// todo retry
console.log('DEBUG: Use AWS SDK V3: CreateFunctionCommand()')
const command = new CreateFunctionCommand(params)
return lambdaClient.send(command)
}

return new Promise((resolve, reject) => {
const request = lambda.createFunction(params, (err, data) => {
if (err) return reject(err)
11,958 changes: 7,722 additions & 4,236 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
"node": ">= 18.0.0"
},
"dependencies": {
"@aws-sdk/client-lambda": "^3.670.0",
"@dotenvx/dotenvx": "^1.14.0",
"archiver": "^7.0.0",
"aws-sdk": "^2.1377.0",
1,653 changes: 1,163 additions & 490 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit d6a5439

Please sign in to comment.