(aws_apigatewayv2): (VpcLink creation failing due to share subnet and security-group-id)
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
During the 'creating CloudFormation changeset' stage of deployment, the deployment fails during the creation step for the VpcLink for a reason that should not be an issue.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
THe VpcLink should be able to be created during deployment as I pass to it an existing VPC with security groups.
### Current Behavior
The deployment fails.
```bash
Resource handler returned message: "For a shared subnet, at least one security-group-id should be provided. (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 50573051-75a5-438c-a6d9
-e9edd75c414c; Proxy: null)" (RequestToken: 33c819bd-427f-6b00-72cc-fff30d2a1d9e, HandlerErrorCode: GeneralServiceException)
```
### Reproduction Steps
```py
from aws_cdk import (
Stack,
aws_ec2 as ec2,
aws_ecs as ecs,
aws_ecs_patterns as ecs_patterns,
aws_apigatewayv2_integrations as integrations,
aws_apigatewayv2 as apigwv2,
)
from constructs import Construct
class ECSFargateStack(Stack):
"""Define deployment stack for ECS and Fargate"""
def __init__(
self,
scope: Construct,
construct_id: str,
vpc_id: str = None,
certificate_arn: str = None,
security_group_ids: list = None,
**kwargs,
):
super().__init__(scope, construct_id, **kwargs)
# bring in VPC information from existing VPC
vpc = ec2.Vpc.from_lookup(self, id="vpc", vpc_id=vpc_id)
# create ECS cluster
cluster = ecs.Cluster(self, id="ffdb-cluster", vpc=vpc)
# Use L3 construct to handle boiler plate
ecs_fargate = ecs_patterns.ApplicationLoadBalancedFargateService(
self,
id="ff-db-alb-fargate-service_pattern",
cluster=cluster, # ensure we are using
desired_count=1, # number of tasks to keep running on the service
load_balancer_name="ff-db-alb", # name of the load balancer
task_image_options=ecs_patterns.ApplicationLoadBalancedTaskImageOptions(
image=ecs.ContainerImage.from_registry("myecr/my-container:latest"),
),
cpu=1024, # 1 vCPU, used by task
memory_limit_mib=2048, # 2 GB
public_load_balancer=False,
service_name="ff-db-service",
)
# create a VPC link
vpc_link = apigwv2.VpcLink(
self,
id="ff-db-vpc-link",
vpc=vpc,
)
# create an HTTP API
http_api = apigwv2.HttpApi(
self,
id="ff-db-http-api",
create_default_stage=True,
default_integration=integrations.HttpAlbIntegration(
id="ff-db-alb-integration",
listener=ecs_fargate.listener,
),
)
# add a route to the HTTP API that forwards requests to the ALB
http_api.add_routes(
path="/{proxy+}",
methods=[apigwv2.HttpMethod.ANY],
integration=integrations.HttpAlbIntegration(
id="ff-db-alb-integration",
listener=ecs_fargate.listener,
),
)
```
### Possible Solution
_No response_
### Additional Information/Context
I am trying to create an ECS Fargate stack with a private application load balancer to deploy an API. I want to create an integration between the private ALB and the Fargate service for an HTTP API to forward requests over.
I am trying to implement the tutorial on [creating an HTTP API with a VPC Link](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-private-integration.html) using AWS CDK.
### CDK CLI Version
2.1007.0 (build d3f6c3c)
### Framework Version
_No response_
### Node.js Version
v22.14.0
### OS
Ubuntu 22.04.5 LTS
### Language
Python
### Language Version
3.11.9
### Other information
_No response_
Contributor guide
Research direction
The entry point is aws_apigatewayv2.VpcLink in the Python reproduction; start by tracing the synthesized VpcLink and CloudFormation properties for an imported VPC with shared subnets. Reproduce the deployment error, then add a regression test and verify that deployment supplies the required security-group-id.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cloud, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100