alexa/ask-cli

Get "ResourceConflictException" after opt-in AWS lambda states update

Closed this issue · 13 comments

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request 
[ ] Other... Please describe: 

Expected Behavior

It should deploy lambda successfully when I opt-in AWS lambda states update.

Current Behavior

I follow the Coming soon: Expansion of AWS Lambda states to all functions to add aws:states:opt-in in function’s description. Running ask deploy will failed and get error message:

[Error]: CliError: The lambda deploy failed for Alexa region "default": ResourceConflictException: The operation cannot be performed at this time. An update is in progress for resource: arn:aws:lambda:${my function id}

If I remove aws:states:opt-in in function’s description, it can deploy normally.

Your Environment and Context

  • ask-cli version: 2.24.1
  • Operating System and version:
  • Node.js version used for development: v15.12.0
  • Yarn version used for development: 1.21.1

@RonWang I can confirm this issue which affects the lambda-deployer workflow. From what I can see, the CLI is currently expecting the Lambda function creation and update process to be blocking as it has been until this change. A wait for the proper State and LastUpdateStatus function properties before continuing the Lambda deployment process needs to be added.

In all, the lambda-deployer workflow will be broken once the general update phase for this change is completed, which is currently stated for December 6th.

I'm having this issue since this morning deploying in the eu-west-1 region.
Is there any way to fix this before Dec 6th?

Set the function description to "aws:states:opt-out" to deploy again.

Any update here? I'm using the lambda-deployer and unless I add aws:states:opt-out to my Lambda description, I'm unable to deploy. aws:states:opt-in and having it both result in the same error noted above. As of 12/6, my workflows will be blocked.

Any updates? I'm also experiencing the same problem as other engineers here. My workflow will be blocked as of 12/6 and this is the main SDK to deploy Alexa Skills with lambda functions.

Looks like it's a problem with how we use revision id when updating lambda function. Tracing that code:

CLI will load the Lambda Function information from AWS and store it in deployState

currentRegionDeployState.lambda = lambdaData.lambda;

Then, when updating the Lambda, the revisionId is extracted from that object:

let { revisionId } = deployState.lambda;

And then uses it when updating the Function:

let { revisionId } = deployState.lambda;
lambdaClient.updateFunctionCode(zipFile, functionName, revisionId, (codeErr, codeData) => {
if (codeErr) {
return callback(codeErr);
}
reporter.updateStatus(`Update a lambda function (${functionName}) in progress...`);
const { runtime } = userConfig;
const { handler } = userConfig;
revisionId = codeData.RevisionId;
lambdaClient.updateFunctionConfiguration(functionName, runtime, handler, revisionId, (configErr, configData) => {

It calls UpdateFunctionConfiguration afterwards but it uses the latest RevisionId:

revisionId = codeData.RevisionId;

From the conversation here, this seems to be related to AWS Lambda States. Reading the docs: https://docs.aws.amazon.com/lambda/latest/dg/functions-states.html

The following operations fail while function creation is pending:

  • Invoke
  • UpdateFunctionCode
  • UpdateFunctionConfiguration
  • PublishVersion

I think the fix is to wait until the state changes before calling UpdateFunctionConfiguration.

Hey all, sorry for the delay on this. I've put together a PR for what I think should fix this issue. Still need to test but would also like some feedback on the desired behavior: #422

I will test this once I get back in to the office. Until then, feel free to check out #422 and run the following commands to install it as your CLI

npm install
npm run prepublishOnly
npm pack
npm install -g ./ask-cli-2.24.1.tgz

Hi @sam-goodwin, thank you for the update on this issue, I will be watching your PR, based on the latest comments sounds like I should wait to update to the newer version, will keep an eye out.

If anyone want to test the PR I submitted above, you can install it using the command below:

npm install -g jsetton/ask-cli#lambda-state-update-fix

Hi @jsetton my tests were successful with your branch, I was able to deploy latest code changes to my lambda function code to AWS without issues. It's looking good on my end. My understanding is that your code still have to finish going through review before a new release can be rolled out correct?

Really appreciate your work so far @jsetton !

My understanding is that your code still have to finish going through review before a new release can be rolled out correct?

This is correct but you can use the version I submitted in the meantime. Since ask-cli checks for the latest available official release each time you run the tool, you will be notified when to switch back to the official one.