Reputation: 394
I have a lambda function in a private subnet, I want to invoke this lambda function by creating an API gateway and this API can only be called by a particular EC2 instance in public subnet (The private and public subnet are in the same VPC) and not by anyone else.
I want to create a Lambda function and API gateway for private communication
Can someone guide/suggest me how to approach this problem.
Upvotes: 2
Views: 1736
Reputation: 361
If you have created VPC and private subnets. 1. Create VPC endpoint for to API gateway. 2. provide 443 to network access to you Security group who is attached with VPC endpoint, other access you can provide whatever you need. 3. Create ApiGateway in private and deploy your resources. 4. create lambda and it should be same VPC, subnets and security group. 5. Also DNS Enalbed in VPS side. Now create your test in lambda function and execute it.
via curl command, you can execute like this
curl -v https://vpc_endpoint_dns/ \
-H 'x-apigw-api-id:apikey' \
-H 'authtoken: lkskdflsdjfoeiru' \
-H 'cache-control: no-cache' \
-H 'postman-token: lkdsfj8495' \
-H 'timestamp: 1649646851'
Upvotes: 1
Reputation: 226
add resource policy to your API with VPC or IP white listing.
for more details refer: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html
Upvotes: 1