From 4e41352cd320d1b84c62b9d716c75de469e9af8f Mon Sep 17 00:00:00 2001 From: togashi Date: Mon, 9 May 2022 15:55:50 +0900 Subject: [PATCH 1/2] organize --- lib/main.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index c9cef55..b1bcbce 100644 --- a/lib/main.js +++ b/lib/main.js @@ -566,6 +566,24 @@ Emulate only the body of the API Gateway event. } } + _waitForLastUpdateStatus(lambda, params, delay = 2, count = 0) { + if (count >= 30) throw Error('asynchronous function update timed out.') + if (params.LastUpdateStatus === 'Successful') return Promise.resolve() + if (count === 0) console.log('=> Waiting for LastUpdateStatus') + return new Promise(resolve => { + setTimeout(resolve, delay * 1000) + }).then(() => { + return lambda.getFunction({ FunctionName: params.FunctionName }).promise() + .catch(err => reject(err)) + .then(data => { + if (data.Configuration.LastUpdateStatus === 'Failed') + return reject(Error('asynchronous function update failure detected.')) + if (data.Configuration.LastUpdateStatus === 'Successful') return + return this._waitForLastUpdateStatus(lambda, data.Configuration, delay, count + 1) + }) + }) + } + _uploadExisting (lambda, params) { const functionCodeParams = Object.assign({ FunctionName: params.FunctionName, @@ -600,14 +618,16 @@ Emulate only the body of the API Gateway event. (err, configResponse) => { if (err) return reject(err) - const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams, (err) => { - if (err) return reject(err) - resolve(configResponse) - }) + return this._waitForLastUpdateStatus(lambda, configResponse).then(() => { + const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams, (err, updateCodeResponse) => { + if (err) return reject(err) + resolve(updateCodeResponse) + }) - updateCodeRequest.on('retry', (response) => { - console.log(response.error.message) - console.log('=> Retrying') + updateCodeRequest.on('retry', (response) => { + console.log(response.error.message) + console.log('=> Retrying') + }) }) } ) From 5bf45aad69d3db777ff418f6e0d9c4062d77abe9 Mon Sep 17 00:00:00 2001 From: togashi Date: Mon, 9 May 2022 16:19:33 +0900 Subject: [PATCH 2/2] patch: ignore tags starts with 'aws:' in _updateTags function --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index c031f58..34c6e86 100644 --- a/lib/main.js +++ b/lib/main.js @@ -856,7 +856,7 @@ they may not work as expected in the Lambda environment. } else { return lambda.listTags({ Resource: functionArn }).promise() .then(data => { - const keys = Object.keys(data.Tags) + const keys = Object.keys(data.Tags).filter(name => !name.startsWith('aws:')) return keys && keys.length > 0 ? lambda.untagResource({ Resource: functionArn, TagKeys: keys }).promise() : Promise.resolve()