ApiGateway has 500 error when Lambda is updating

0

I am seeing a rare race condition. Sometimes, if I update my image-based Lambda to have a new image, the ApiGateway api that is triggering the Lambda returns the following error:

(f654758f-d377-4222-a4c3-766325f0de32) Lambda invocation failed with status: 409. Lambda request id: 1e69c921-26ce-4c4d-81ad-183264a08c59
(f654758f-d377-4222-a4c3-766325f0de32) Execution failed due to configuration error: The operation cannot be performed at this time. The function is currently in the following state: Pending
(f654758f-d377-4222-a4c3-766325f0de32) Method completed with status: 500

Here is how I'm updating the Lambda which causes the race condition to occur:

# publish the new docker image to the function
aws lambda update-function-code --publish --function-name "$name" --image-uri "$image"
# update my alias to the new published version
aws lambda update-alias --name "$stage" --function-name "$name" --function-version "$version"

I must be doing something wrong, because if a Lambda image or alias can't be updated atomically, that is a deal-breaker for reliable deployments.

1개 답변
2
수락된 답변

Lambda functions can be in one of several states. This happens during function creation and update.

I assume your API is configured to invoke a specific lambda alias. It seems you are moving your alias before the new lambda version is in the Active state. You should be update the alias only after the function gets into the Active state.

profile pictureAWS
전문가
Uri
답변함 2년 전
  • Yes, that would make sense. I have added the following commands before I update the alias pointer, and it seems to clear up the issue:

    aws lambda wait function-updated --function-name "$name"
    aws lambda wait function-active --function-name "$name"
    

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠