I'm getting the following error when trying to call create_topic()
in Boto3. It works locally in sam running sam local invoke
, but once deployed, it times out.
ConnectTimeoutError: Connect timeout on endpoint URL: "https://sns.us-east-2.amazonaws.com/"
Here's the code:
sns = boto3.client('sns')
topic_name = f'my-sns-topic-{ENVIRONMENT}'
topic = sns.create_topic(Name=topic_name)
notification_channel = {"SNSTopicArn": topic["TopicArn"], "RoleArn": "arn:aws:iam::my-role"}
My Lambda function is on private subnets. The function shouldn't require any access to the internet, so I think private subnets are ok (?). All my resources are on the same VPC.
Does the lambda function have to be on a public subnet to reach SNS? I tried adding a 0.0.0.0/0
route mapped to my internet gateway to the route table associated with the private subnet, but that didn't help.
What am I missing?
CodePudding user response:
My Lambda function is on private subnets. The function shouldn't require any access to the internet,
If your lambda function is deployed in a VPC that does not have internet connectivity, then your lambda function will be unable to reach the service endpoint (sns.us-east-2
) over the public internet, as you would expect.
If you want private connectivity to the service, then you need to provision a VPC interface endpoint for the service and deploy it in the same VPC as your lambda.