Skip to content
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

fix(_uploadExisting): fix function update errors #575

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
43 changes: 22 additions & 21 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ Emulate only the body of the API Gateway event.
}
}

_uploadExisting (lambda, params) {
async _uploadExisting (lambda, params) {
const functionCodeParams = Object.assign({
FunctionName: params.FunctionName,
Publish: params.Publish
Expand Down Expand Up @@ -594,29 +594,30 @@ Emulate only the body of the API Gateway event.
delete functionConfigParams.Layers
}

return new Promise((resolve, reject) => {
const updateConfigRequest = lambda.updateFunctionConfiguration(
functionConfigParams,
(err, configResponse) => {
if (err) return reject(err)

const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams, (err) => {
if (err) return reject(err)
resolve(configResponse)
})
const updateConfigRequest = lambda.updateFunctionConfiguration(functionConfigParams)
updateConfigRequest.on('retry', (response) => {
console.log(response.error.message)
console.log('=> Retrying')
})
const updateConfigResponse = await updateConfigRequest.promise()

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

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

return updateConfigResponse
}

_uploadNew (lambda, params) {
Expand Down
2 changes: 1 addition & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const lambdaMockSettings = {
addPermission: {},
getFunction: {
Code: {},
Configuration: {},
Configuration: { LastUpdateStatus: 'Successful' },
FunctionArn: 'Lambda.getFunction.mock.FunctionArn'
},
createFunction: {
Expand Down