I followed this:
- https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html
- https://aws.amazon.com/blogs/compute/introducing-amazon-api-gateway-private-endpoints/ tutorials
to a tee to create a private link between my REST API endpoint.
Essentially, steps that I have done:
Converted a (previously working) Edge API to a private API (via the AWS API Gateway Console)
Created a VPC with 2 public subnets and 2 private subnets using this template: https://s3.amazonaws.com/computeblog-us-east-1/apigateway-private-endpoints/BaseVPC.template
Confirmed that DNS naming and DNS resolution are enabled on the VPC.
Created a VPC endpoint that attached to the VPC created above. Private DNS is enabled.
Added this resource policy to the API, then redeployed it:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:us-west-2:{aws-account-id}:{rest-api-id}/*/*/*",
"Condition": {
"StringNotEquals": {
"aws:sourceVpce": "vpce-{endpoint}"
}
}
},
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:us-west-2:{aws-account-id}:{rest-api-id}/*/*/*"
}
]
}
I then used a Java Client created by the AWS SDK: https://aws.amazon.com/sdk-for-java/ to invoke the API, and got hit with this error:
com.amazonaws.SdkClientException: Unable to execute HTTP request: {rest-api-id}.execute-api.us-west-2.amazonaws.com
...
Caused by: java.net.UnknownHostException: {rest-api-id}.execute-api.us-west-2.amazonaws.com
Same issue happened when I used Postman.
As indicated in https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-api-test-invoke-url.html as well as API Gateway console, if I have private DNS enabled, I should be able to invoke the API using the url.
Do I misunderstand something? What is the correct way to be able to successfully invoke the API?
EndpointSG sg-{number}, is that the correct one to connect to? - Katiecurlif you can indeed invoke your api correctly. Then you can take it from there how to use postman (e.g. ssh tunnel). - Marcin