aws / aws/aws-cdk

apigatewayv2: Error referencing integration_id when creating route

Open
#30,512 4 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-apigatewayv2 bug needs-cfn p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When creating an integration for a websocket api to create a route you need to have the id of the integration you want to attach, but there are errors that prevent deployment.

This is the error I am getting from referencing get_cases_integration.attr_id:
[Error] /Resources/TestGetCasesRoute/Properties/Target/Fn::Join/1/1/Fn::GetAtt: Resource type AWS::ApiGatewayV2::Integration does not support attribute {Id}

attr_id is shown as an attribute I should be able to use in the documentation here: https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_apigatewayv2/CfnIntegration.html

and id is shown in the cloudformation docs as well
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-integration.html

Actually using the attribute results in an error though.

Hardcoding the target works fine as shown in the second commented out target in the route.

``` python
websocket_api = apigwv2.WebSocketApi(
self,
"CPP Websocket API",
connect_route_options=apigwv2.WebSocketRouteOptions(
integration=apigwv2_integrations.WebSocketLambdaIntegration(
"ConnectIntegration",
handler=websocket_lambda,
),
authorizer=aws_apigatewayv2_authorizers.WebSocketLambdaAuthorizer(
"Websocket Authorizer",
handler=websocket_authorizer_lambda,
identity_source=[
"route.request.querystring.token",
],
authorizer_name="Websocket_Authorizer",
),
),
disconnect_route_options=apigwv2.WebSocketRouteOptions(
integration=apigwv2_integrations.WebSocketLambdaIntegration(
"DisconnectIntegration",
handler=websocket_lambda,
),
),
description="Websocket API For CPP",
)

get_cases_model = apigwv2.CfnModel(
self,
"Get Cases Model",
api_id=websocket_api.api_id,
name="GetCases",
schema={
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Test",
"type": "object",
"properties": {
"action": {
"type": "string",
},
"email": {
"type": "string",
},
},
"required": [
"action",
"email",
],
},
content_type="application/json",
description="Get Cases Model description",
)

get_cases_integration = apigwv2.CfnIntegration(
self,
"Test Get Cases Integration",
api_id=websocket_api.api_id,
integration_type="AWS_PROXY",
# the properties below are optional
connection_type="INTERNET",
# content_handling_strategy="contentHandlingStrategy",
# credentials_arn="credentialsArn",
description="get_cases integration",
integration_method="POST",
# integration_uri=websocket_lambda.function_arn,
integration_uri=f"arn:aws:apigateway:{region}:lambda:path/2015-03-31/functions/arn:aws:lambda:{region}:{account}:function:{websocket_lambda.function_name}/invocations",
# passthrough_behavior="passthroughBehavior",
# payload_format_version="payloadFormatVersion",
request_parameters={},
# request_templates=request_templates,
# template_selection_expression="templateSelectionExpression",
timeout_in_millis=29000,
)

get_cases_route = apigwv2.CfnRoute(
self,
"Test Get Cases Route",
api_id=websocket_api.api_id,
route_key="test_get_cases",
# the properties below are optional
api_key_required=False,
# authorization_scopes=["authorizationScopes"],
# authorization_type="authorizationType",
# authorizer_id="authorizerId",
model_selection_expression="${request.body.action}",
# operation_name="GetCases",
request_models={
"GetCases": get_cases_model.name,
},
# request_parameters=request_parameters,
# route_response_selection_expression="routeResponseSelectionExpression",
target=f"integrations/{get_cases_integration.attr_id}",
# target="integrations/3aupm6i",
)
```

### Expected Behavior

I should be able to get the integration id for use with the route.

### Current Behavior

The attribute I am trying to use is invalid (attr_id)

### Reproduction Steps

Use above code.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.145.0 (build fdf53ba)

### Framework Version

_No response_

### Node.js Version

v20.14.0

### OS

Ubuntu 24.04

### Language

Python

### Language Version

Python 3.12.3

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the apigwv2.CfnIntegration and CfnRoute entry points and compare the attr_id exposed by the Python binding with the AWS CloudFormation documentation linked in the issue. Trace the generated resource attributes and deployment output; done means a route can reference the integration through its ID without producing an unsupported-attribute error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
api, cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.