aws / aws/aws-cdk

aws_apigatewayv2_alpha: Incorrect Lambda permission when adding WebSocketLambdaIntegration

Open
#22,940 5 comments 5 reactions 1 assignee Claimed by @otaviomacedo View on GitHub
@aws-cdk/aws-apigatewayv2 bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

After creating a web socket api, if I use the *add_route* method where the integration is being created with the WebSocketLambdaIntegration from aws_apigatewayv2_integrations_alpha the permission attached to the lambda in the template looks something like:

```
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":execute-api:us-east-1:111111111111:",
{
"Ref": "WebSocketApiTestWebsocket418E978B"
},
"/*/*sendmessage"
]
]
}
```
This results in an error in the lambda console that looks like:
websocket_lambda_error

But when I attach my lambda through the console the permission attached to the lambda looks like: `arn:aws:execute-api:{region}:{account id}:p1bg873k5e/*/sendmessage`

### Expected Behavior

I would expect the output of the Template to have a permission that looks like:

```
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":execute-api:us-east-1:111111111111:",
{
"Ref": "WebSocketApiTestWebsocket418E978B"
},
"/*/sendmessage"
]
]
}
```
so `/*/sendmessage` vs `/*/*sendmessage`

### Current Behavior

There's an extra * in the output template of the source arn

### Reproduction Steps

```
from aws_cdk import (
App,
Duration,
Environment,
Stack,
aws_apigatewayv2_alpha as apigateway,
aws_apigatewayv2_integrations_alpha as apigateway_integration,
aws_lambda as lambda_fn
)

app = App()
env = Environment(account='', region='')
stack = Stack(app, 'TestStack', env=env)

api_kwargs = {
'scope': stack,
'id': 'WebSocketApi',
'api_name': 'WebsocketTest',
'route_selection_expression': '$request.body.action'
}

ws_api = apigateway.WebSocketApi(**api_kwargs)

l_code = lambda_fn.Code.from_asset(path='./')
l_kwargs = {
'scope': stack,
'id': 'LambdaFunction',
'code': l_code,
'handler': 'lambda_handler',
'runtime': lambda_fn.Runtime('PYTHON_3_9'),
'timeout': Duration(60)
}

l_function = lambda_fn.Function(**l_kwargs)

route_kwargs = {
'route_key': 'sendmessage',
'integration': apigateway_integration.WebSocketLambdaIntegration(id='WebsocketIntegration', handler=l_function)
}
ws_api.add_route(**route_kwargs)

app.synth()
```

### Possible Solution

Fix the format of the arn in the lambda permission

### Additional Information/Context

_No response_

### CDK CLI Version

2.41.0

### Framework Version

_No response_

### Node.js Version

2.40.0

### OS

Mac

### Language

Python

### Language Version

3.9

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.