aws-cdk: (custom-resources): StateNotFoundError: State functionActiveV2 not found
Please add your +1 👍 to let us know you have encountered this
Status: RESOLVED
Overview:
Any customer using custom resources may encounter the error when the custom resource handler lambda becomes INACTIVE.
Root cause: Lambda installs the SDK at 2.1055.0, but functionActiveV2 doesn’t exist until 2.1080.0. It was reported in ap-south-2 but can happen in any region.
The error occurs anytime the custom resource provider framework fails to invoke the custom resource handler lambda. In that event, the framework will use functionActiveV2 to wait for the lambda to become active again. However, the call to functionActiveV2 will fail in the provider lambda because of root cause described above.
Complete Error Message:
Received response status [FAILED] from custom resource. Message returned: StateNotFoundError: State functionActiveV2 not found.
Workaround:
Solution:
use functionActive instead.
https://github.com/aws/aws-cdk/pull/25228
Related Issues:
https://github.com/aws/aws-cdk/issues/23862#issuecomment-1445756934
Original Issue
Describe the bug
When deploying 10+ custom resources in ap-south-2, it fails with StateNotFoundError: State functionActiveV2 not found error as below:
- It’s fine to deploy 10+ custom resources in other AWS regions such as
us-east-1orap-northeast-1. Onlyap-south-2fails in this case. - When deploying with <10 custom resources,
ap-south-2will be fine with no error.
Expected Behavior
The provided code above should deploy in ap-south-2.
Current Behavior
Reproduction Steps
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import * as lambda from "aws-cdk-lib/aws-lambda";
import { CustomResource } from "aws-cdk-lib";
import * as cr from "aws-cdk-lib/custom-resources";
export class DummyLambdaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const onEventHandler = new lambda.Function(this, 'OnEventHandler', {
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromInline(`exports.onEvent = () => { return }`),
handler: 'index.onEvent',
})
const provider = new cr.Provider(this, "Provider", {
onEventHandler,
});
const numResources = 10
for (let i = 0; i < numResources; i++) {
new CustomResource(this, `CR${i}`, {
serviceToken: provider.serviceToken,
});
}
}
}
Possible Solution
There might be some restrictions in ap-south-2.
Additional Information/Context
No response
CDK CLI Version
2.66.1 (build 539d036)
Framework Version
No response
Node.js Version
v16.17.0
OS
Linux
Language
Typescript
Language Version
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 15
- Comments: 17 (6 by maintainers)
Commits related to this issue
- fix(custom-resources): State functionActiveV2 not found (#25228) Replaces `functionActiveV2` with `functionActive`. `functionActiveV2` is not available in SDK versions < 2.1080.0, but the one that... — committed to aws/aws-cdk by comcalvi a year ago
- fix(eks): policy does not exist or is not attachable in China and GovCloud regions (#25215) Reopening this PR because #25170 was closed by accident. As ECR Public is not available in China regions a... — committed to aws/aws-cdk by pahud a year ago
- fix(custom-resources): State functionActiveV2 not found (#25228) Replaces `functionActiveV2` with `functionActive`. `functionActiveV2` is not available in SDK versions < 2.1080.0, but the one that... — committed to aws/aws-cdk by comcalvi a year ago
- chore: notice for https://github.com/aws/aws-cdk/issues/24358 (#176) CLI notice for #24358. Inactive custom resource provider framework lambdas will cause errors due to Lambda's default SDK version (... — committed to cdklabs/aws-cdk-notices by comcalvi a year ago
It seems like this CDK commit is using the functionActiveV2 state from the JS SDK: https://github.com/aws/aws-cdk/commit/def2971d91eedbd327d3acec201d902376129f25
Then the change in CDK v2.60.0 switched off installLatestAwsSdk by default for custom resources, and from the PR it seems the default SDK version packaged by Lambda is 2.1055.0: https://github.com/aws/aws-cdk/pull/23591
But the functionActiveV2 state seems to have been introduced in the SDK in version v2.1080.0 from this commit in the JS SDK repo: https://github.com/aws/aws-sdk-js/commit/488f6ad83b02efcc1b4867caeba3ccd44b65be58
So it seems the installLatestAwsSdk change is the culprit for the issue we are experiencing
This seems like the right root cause as far as I can tell. I guess the reason this shows in ap-south-2 and not other regions is for some reason deploying certain number of custom resources causes some backup in lambda function creation that causes the functions to be pending, where in other regions we actually just never call
waitFor('functionActiveV2'because the invoke doesn’t fail…I guess the easiest fix would be changing to use
functionActiveinstead offunctionActiveV2.