top of page
Writer's pictureVaibhav Deshpande

Tutorial blog to create an HTTP API to access Amazon ECS service running in Amazon VPC

Learning Objectives: -

  • Learn to use CloudFormation template to create VPC and ECS service.

  • Learn to use API Gateway to create an HTTP API.

  • Learn to integrate an HTTP API with ECS service running in VPC.

Step 1: Download and unzip this file

Step 2: In AWS management console, go to CloudFormation console.

Choose Create stack and then choose with new resources (standard).

For Specify template, choose Upload a template file.

Select the template that you downloaded.

Choose Next.

For Stack name, enter http-api-private-integrations-tutorial and then choose Next.

For Configure stack options, choose Next.

For Capabilities, acknowledge that AWS CloudFormation can create IAM resources in your account.

Choose Submit.

AWS CloudFormation provisions the resources specified in the template. It can take a few minutes to finish provisioning your resources. When the status of your AWS CloudFormation stack is CREATE_COMPLETE, you're ready to move on to the next step.

Step 3: In AWS management console, go to API gateway.

Choose VPC links and then choose Create.

For Choose a VPC link version, select VPC link for HTTP APIs.

For Name, enter private-integrations-tutorial.

For VPC, choose the VPC that you created in step 1. The name should start with PrivateIntegrationsStack.

For Subnets, select the two private subnets in your VPC. Their names end with PrivateSubnet.

Choose Create.

Step 4: In API Gateway, choose APIs.

Choose Create API, and then for HTTP API, choose Build.

For API name, enter http-private-integrations-tutorial.

Choose Next.

For Configure routes, choose Next to skip route creation. You create routes later.

Review the stage that API Gateway creates for you. API Gateway creates a $default stage with automatic deployments enabled, which is the best choice for this tutorial. Choose Next.

Choose Create.

Step 5: In API Gateway, choose your API.

Choose Routes.

For Method, choose ANY.

For the path, enter /{proxy+}. The {proxy+} at the end of the path is a greedy path variable. API Gateway sends all requests to your API to this route.

Choose Create.

Step 6: In API Gateway, choose your API.

Choose Integrations.

Choose Manage integrations and then choose Create.

For Attach this integration to a route, select the ANY /{proxy+} route that you created earlier.

For Integration type, choose Private resource.

For Integration details, choose Select manually.

For Target service, choose ALB/NLB.

For Load balancer, choose the load balancer that you created with the AWS CloudFormation template in Step 1. It's name should start with http-Priva.

For Listener, choose HTTP 80.

For VPC link, choose the VPC link that you created in Step 2. It's name should be private-integrations-tutorial.

Choose Create.

To verify that your route and integration are set up correctly, select Attach integrations to routes. The console shows that you have an ANY /{proxy+} route with an integration to a VPC Load Balancer.

Step 7: In API Gateway, choose your API.

Choose your API.

Note your API's invoke URL.

In a web browser, go to your API's invoke URL.

The full URL should look like https://abcdef123.execute-api.us-east-2.amazonaws.com.

Your browser sends a GET request to the API.

Verify that your API's response is a welcome message that tells you that your app is running on Amazon ECS.


Note: Delete API Gateway and CloudFormation if no longer in use.


Was this document helpful? How can we make this document better. Please provide your insights. You can download PDF version for reference.


For your aws certification needs or for aws learning contact us.


Comments


bottom of page