Skip to content

Commit

Permalink
fix(_uploadExisting): fix function update errors
Browse files Browse the repository at this point in the history
Immediately after updating the settings, `Configuration.LastUpdateStatus` is `InProgress`.
If you update the code in that state, you will get an error.
You need to update the code after the `Configuration.LastUpdateStatus` becomes `Successful`.

I've fixed it to wait until it becomes `Successful`.
  • Loading branch information
abetomo committed Sep 24, 2021
1 parent 8175737 commit 15f73cb
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 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)
})

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

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

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

0 comments on commit 15f73cb

Please sign in to comment.