Skip to content

AWS SDK V3: Migrate CreateFunction to v3 #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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)
Expand Down
Loading