API GW Websockets and public subnets

0

Hi, I have a publicly available API GW Websockets, I have a lambda and ec2 instance in a VPC in a public subnet with IGW and correct routing tables. I have all security groups opened but when I try to post_to_connection using boto3.client('apigatewaymanagementapi') the connection timeouts in Lambda, or I get this error in EC2 when I run

$ aws apigatewaymanagementapi  post-to-connection --data 'hello' --connection-id 'OuoMyd3eDoECJpQ=' --region eu-west-1

Could not connect to the endpoint URL: "https://execute-api.eu-west-1.amazonaws.com/@connections/OuoMyd3eDoECJpQ%3D

Not sure what's wrong, I tried putting the EC2 into a private subnet with a NAT gateway and VCPE endpoint for API GW but no luck.

EDIT: I found the issue with the aws-cli command, I actually had to specify the endpoint_url pointing to the connection_url of the API GW. This works, but for some reason I still can't post any messages from within the lambda which is on the same VPC and public subnet.

1개 답변
2
수락된 답변

When attaching Lambda functions to a VPC they do not receive a public IP. For them to be able to communicate outside the VPC they need to be placed in a private subnet and use a VPC Endpoint or a NAT Gateway.

profile pictureAWS
전문가
Uri
답변함 2년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠