bug: CloudFormation (v2 engine): a custom resource's Update request carries PhysicalResourceId: null and no OldResourceProperties, so CDK BucketDeployment fails on every update
#92
mattiarossi
started this conversation in
Bugs (AWS)
Replies: 1 comment
|
Hi @mattiarossi , thanks for the very detailed report and the minimal template. It made this easy to confirm. I reproduced it on the latest dev image. On a stack update, the v2 engine sends the custom resource's Update request with PhysicalResourceId: null and no OldResourceProperties, so the stack rolls back. On AWS, the same template gets the Create's id and OldResourceProperties, and the stack reaches UPDATE_COMPLETE. I've passed it to our engineering team with a reproduction. I'll update this thread when there's progress or a fix to test. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Current behavior
When a stack update changes a property of a Lambda-backed custom resource, the v2 CloudFormation engine invokes the provider with
RequestType: "Update"andPhysicalResourceId: null. The key is present but empty, although the stack stores the id the provider returned at Create (describe-stack-resourceshows it before and after).OldResourcePropertiesis missing from every Update request.A provider that reads the id fails the update, and the stack rolls back. The AWS CDK
BucketDeploymenthandler (aws-s3-deployment,index.py) is one such provider. It answersinvalid request: request type is 'Update' but 'PhysicalResourceId' is not defined. Every CDK app whose bucket deployment's source changes therefore cannot be redeployed. Our case is an Amplify Gen 2 sandbox, where each GraphQL schema change updatesmodelIntrospectionSchemaBucketDeployment(Custom::CDKBucketDeployment). The only way out is to delete the stack, or reset the instance, and deploy from scratch.The rollback's Update request does carry the id, and so does the Delete request. Only the forward Update request is missing it.
Reproduction, one stack
The provider below applies the CDK handler's own check and logs each request it receives. Only
Versionchanges between the create and the update.template.ymlThe attached
repro-cfn-custom-resource-update.shruns the same steps, prints the requests from the provider's log, and deletes the stack. Its output on LocalStack 2026.11.0.dev1384 (run 2026-11-24):PhysicalResourceId: null; noOldResourcePropertiesOldResourceProperties: {"ServiceToken": …, "Version": "1"}OldResourcePropertiesOldResourceProperties: {…, "Version": "2"}UPDATE_ROLLBACK_COMPLETEUPDATE_COMPLETEThe emulator's log at the failure, from the Amplify case:
Expected behavior
The AWS custom resource reference (CloudFormation User Guide, "Update requests" under the custom resource request reference) describes the Update request this way.
PhysicalResourceIdis the value the provider returned for the resource, and the provider compares it to decide between an in-place update and a replacement.OldResourcePropertiesholds the properties declared before the update. On AWS, the reproduction endsUPDATE_COMPLETEwith no rollback, and the forward Update receives the Create's id andOldResourceProperties.Version = "1".The rollback request is built with the id, so the engine has the stored id. Only the forward Update request is built without it. The provider is
localstack.pro.core.services.cloudformation.resource_providers.aws_cloudformation_customresource, called fromengine/v2/change_set_model_executor.How are you starting LocalStack?
Docker Compose (LocalStack Pro,
localstack/localstack:dev2026.11.0.dev1384,PERSISTENCE=1, the default CloudFormation engine), with the AWS CLI from a workstation. The reproduction creates one stack and deletes it.Why it matters
Every AWS CDK app that uses
BucketDeployment(or any provider following the custom resource contract, such ascr.Providerhandlers and Powertools custom resources) can be created once on LocalStack and never updated in place. Amplify Gen 2 places aBucketDeploymentin its data stack for the model introspection schema, so every GraphQL schema change in a sandbox rolls back. The only route left is to reset the emulator and deploy from scratch. That gives new Cognito pools, API ids and hosted zones each time, and every by-hand emulator state is lost. Since 2026.6 removed the legacy engine (PROVIDER_OVERRIDE_CLOUDFORMATION=engine-legacyis ignored), no configuration avoids it.Environment
localstack/localstack:dev, Pro token); the same failure on 2026.11.0.dev1137 and dev1142 (2026-11-21), through the Amplify sandboxnpx ampx sandbox(Amplify Gen 2) for the original caseAll reactions