-
When creating a RestApi or Resource level construct and adding a CORS preflight option in python, the cloudformation deployment fails due to method duplication in the CDK-generated json cloudformation template. Both these code snippets synthesize and function properly (CORS works) using sam local start-api ... on localhost:5555 while the browser runs on localhost:3000. We also return
...
api_lambda_integration = apigateway.LambdaIntegration(handler=hal_lambda_api)
rest_api = apigateway.RestApi(self, “hal-api”, # api runs on port 5555 via sam local start-api...
rest_api_name=“HAL Service”,
description=f”This service updates on {target_s3_bucket_name}“,
default_cors_preflight_options=apigateway.CorsOptions(
allow_methods=[‘DELETE’, ‘GET’, ‘HEAD’, ‘OPTIONS’, ‘PATCH’, ‘POST’, ‘PUT’],
allow_origins=[
...valid top-level URLs just hidden here...
‘http://localhost:3000/’],
allow_headers=[‘Content-Type’, ‘Authorization’, ‘X-Amz-Date’, ‘X-Api-Key’,
‘X-Amz-Security-Token’, ‘Api-Auth-Token’],
max_age=Duration.seconds(600))
) AND/OR accounts_and_org_data_test = rest_api.root.add_resource(path_part=“accountsandorgdatatest”)
accounts_and_org_data_test.add_cors_preflight(
allow_methods=[‘DELETE’, ‘GET’, ‘HEAD’, ‘OPTIONS’, ‘PATCH’, ‘POST’, ‘PUT’],
allow_origins=[
...valid top-level URLs just hidden here...
‘http://localhost:3000/’],
allow_headers=[‘Content-Type’, ‘Authorization’, ‘X-Amz-Date’, ‘X-Api-Key’,
‘X-Amz-Security-Token’, ‘Api-Auth-Token’],
max_age=Duration.seconds(600)
)
accounts_and_org_data_test.add_method(http_method=“GET”,
integration=api_lambda_integration)
... Yet, when this same CDK code and synthesized template is deployed to AWS, we receive method already exists for some cloudformation resource(s) during cdk deploy. The AWS case ticket for this issue is 10678669981. This appears to be a CDK cloudformation script generation bug. Has anyone encountered this issue? If so, do you know how to correct, other than using contract-first with SpecRestApi and using a known-to-work openapi.yaml pattern, which is commonly used in SAM? Here's the exact cloudformation event response: Error: Stack Deployments Failed: Error: The stack named HalApiDevStack failed to deploy: UPDATE_ROLLBACK_COMPLETE:
Method already exists for this resource (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID:
4ddde26e-d350-4a99-bfc1-550ff6ff1233; Proxy: null), Method already exists for this resource (Service: AmazonApiGateway;
Status Code: 409; Error Code: ConflictException; Request ID: f71fd9b7-49f2-4d15-984f-afeaa95d06b5; Proxy: null), Method
already exists for this resource (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID:
ce07e8ed-3dca-49da-a3aa-293c4b85e905; Proxy: null), Method already exists for this resource (Service: AmazonApiGateway;
Status Code: 409; Error Code: ConflictException; Request ID: 8eb6c098-73ac-4776-9ee0-73535fc03a0f; Proxy: null) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Converted this into an issue for the team to triage. |
Beta Was this translation helpful? Give feedback.
-
@bmckinle Can you specify which CFN resource is being double generated by which part of the CDK code |
Beta Was this translation helpful? Give feedback.
-
@bmckinle Also, it will be great if you can provide following info:
|
Beta Was this translation helpful? Give feedback.
-
After working with Eman@AWSTechSupport, simply running a cdk destroy on the entire stack and then redeploying eliminated the duplicate method error. I was able to make CorsOptions adjustments in the RestApi call and still redeploy without redeploying from scratch. This is important as complete redeployment is overly time-consuming (~30 minutes). At this stage, it appears that the cloudformation script generated from cdk, along with the currently deployed stack state, conspired to create this "bug". For now, this resolves the issue. |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Converted this into an issue for the team to triage.