Skip to content
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
28 changes: 12 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const { createNamespace } = require('continuation-local-storage')
* The default retry count is 3, and only retryable errors will be retried.
* https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html
*/
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda')
const {
LambdaClient,
CreateFunctionCommand,
GetFunctionCommand,
UpdateFunctionCodeCommand,
UpdateFunctionConfigurationCommand
} = require('@aws-sdk/client-lambda')

const maxBufferSize = 50 * 1024 * 1024

Expand Down Expand Up @@ -671,28 +677,18 @@ Emulate only the body of the API Gateway event.
delete functionConfigParams.Layers
}

const updateConfigRequest = lambda.updateFunctionConfiguration(functionConfigParams)
updateConfigRequest.on('retry', (response) => {
console.log(response.error.message)
console.log('=> Retrying')
})
const updateConfigResponse = await updateConfigRequest.promise()
const updateConfigResponse = await lambda.send(new UpdateFunctionConfigurationCommand(functionConfigParams))

// Wait for the `Configuration.LastUpdateStatus` to change from `InProgress` to `Successful`.
const getFunction = new GetFunctionCommand({ FunctionName: params.FunctionName })
for (let i = 0; i < 10; i++) {
const data = await lambda.getFunction({ FunctionName: params.FunctionName }).promise()
const data = await lambda.send(getFunction)
if (data.Configuration.LastUpdateStatus === 'Successful') {
break
}
await new Promise((resolve) => setTimeout(resolve, 3000))
}

const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams)
updateCodeRequest.on('retry', (response) => {
console.log(response.error.message)
console.log('=> Retrying')
})
await updateCodeRequest.promise()
lambda.send(new UpdateFunctionCodeCommand(functionCodeParams))

return updateConfigResponse
}
Expand Down Expand Up @@ -1017,7 +1013,7 @@ they may not work as expected in the Lambda environment.
FunctionName: params.FunctionName
}).then((existingEventSourceList) => {
return Promise.all([
this._uploadExisting(lambda, params).then((results) => {
this._uploadExisting(lambdaClient, params).then((results) => {
console.log('=> Done uploading. Results follow: ')
console.log(results)
return results
Expand Down
13 changes: 11 additions & 2 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ awsMock.setSDK(path.resolve('node_modules/aws-sdk'))

// Migrating to v3.
const { mockClient } = require('aws-sdk-client-mock')
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda')
const {
LambdaClient,
CreateFunctionCommand,
GetFunctionCommand,
UpdateFunctionCodeCommand,
UpdateFunctionConfigurationCommand
} = require('@aws-sdk/client-lambda')
const mockLambdaClient = mockClient(LambdaClient)
const lambdaClient = new LambdaClient({ region: 'us-east-1' })

Expand Down Expand Up @@ -166,6 +172,9 @@ describe('lib/main', function () {
// for sdk v3
mockLambdaClient.reset()
mockLambdaClient.on(CreateFunctionCommand).resolves(lambdaMockSettings.createFunction)
mockLambdaClient.on(GetFunctionCommand).resolves(lambdaMockSettings.getFunction)
mockLambdaClient.on(UpdateFunctionCodeCommand).resolves(lambdaMockSettings.updateFunctionCode)
mockLambdaClient.on(UpdateFunctionConfigurationCommand).resolves(lambdaMockSettings.updateFunctionConfiguration)
})
after(() => {
_awsRestore()
Expand Down Expand Up @@ -1577,7 +1586,7 @@ describe('lib/main', function () {
describe('_uploadExisting', () => {
it('simple test with mock', () => {
const params = lambda._params(program, null)
return lambda._uploadExisting(awsLambda, params).then((results) => {
return lambda._uploadExisting(lambdaClient, params).then((results) => {
assert.deepEqual(results, lambdaMockSettings.updateFunctionConfiguration)
})
})
Expand Down
Loading