Skip to content

Commit 9e8c6ea

Browse files
authored
Merge pull request #2659 from vamsipulikonda/vamsipulikonda-rest-api-with-alb
New Pattern - Rest API with private ALB - workaround
2 parents f062793 + 2de2e48 commit 9e8c6ea

File tree

5 files changed

+509
-0
lines changed

5 files changed

+509
-0
lines changed

rest-api-private-alb-integration.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"title": "REST API Integration with Private ALB integration",
3+
"description": "This pattern explains workaround on how to integrate an API Gateway REST API with an Application Load Balancer.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "AWS SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"To work around this limitation for private ALBs, a multi-step approach is necessary",
11+
"1. Use an API Gateway VPC to integrate your API with a private Network Load Balancer.",
12+
"2. Use the Network Load Balancer to forward the API request to the private Application Load Balancer",
13+
"3. Application Load Balancer will forward the traffic to Lambda Function configured on HTTPS listener."
14+
]
15+
},
16+
"gitHub": {
17+
"template": {
18+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/rest-api-alb-integration-workaround",
19+
"templateURL": "serverless-patterns/rest-api-alb-integration-workaround",
20+
"projectFolder": "rest-api-alb-integration-workaround",
21+
"templateFile": "template.yaml"
22+
}
23+
},
24+
"resources": {
25+
"bullets": [
26+
{
27+
"text": "How do I integrate an API Gateway REST API with an Application Load Balancer",
28+
"link": "https://repost.aws/knowledge-center/api-gateway-application-load-balancers"
29+
}
30+
]
31+
},
32+
"deploy": {
33+
"text": [
34+
"sam deploy"
35+
]
36+
},
37+
"testing": {
38+
"text": [
39+
"Once the application is deployed, retrieve the API URL provided as output and open it in a browser page."
40+
]
41+
},
42+
"cleanup": {
43+
"text": [
44+
"Delete the stack: <code>sam delete</code>."
45+
]
46+
},
47+
"authors": [
48+
{
49+
"name": "Vamsi Pulikonda",
50+
"image": "https://raw.githubusercontent.com/vamsipulikonda/my-photo/main/vamsi-photo.jpg",
51+
"linkedin": "vamsipulikonda",
52+
"bio": "I am a cloud computing enthusiast working as a Cloud Engineer at Amazon Web Services."
53+
}
54+
],
55+
"patternArch": {
56+
"icon1": {
57+
"x": 15,
58+
"y": 50,
59+
"service": "apigw",
60+
"label": "Amazon API Gateway"
61+
},
62+
"icon2": {
63+
"x": 43,
64+
"y": 50,
65+
"service": "alb",
66+
"label": "Network Load Balancer"
67+
},
68+
"icon3": {
69+
"x": 70,
70+
"y": 50,
71+
"service": "alb",
72+
"label": "App. Load Balancer"
73+
},
74+
"icon4": {
75+
"x": 92,
76+
"y": 50,
77+
"service": "lambda",
78+
"label": "AWS Lambda"
79+
},
80+
"line1": {
81+
"from": "icon1",
82+
"to": "icon2"
83+
},
84+
"line2": {
85+
"from": "icon2",
86+
"to": "icon3"
87+
},
88+
"line3": {
89+
"from": "icon3",
90+
"to": "icon4"
91+
}
92+
}
93+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# REST API Integration with Private ALB - Workaround
2+
3+
This pattern explains how to integrate an API Gateway REST API with an Application Load Balancer.
4+
5+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
6+
7+
## Requirements
8+
9+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
10+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
11+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
12+
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
13+
14+
## Deployment Instructions
15+
16+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
17+
```
18+
git clone https://github.com/aws-samples/serverless-patterns
19+
```
20+
1. Change directory to the pattern directory:
21+
```
22+
cd rest-api-alb-integration-workaround
23+
```
24+
1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
25+
```
26+
sam deploy --guided
27+
```
28+
1. During the prompts:
29+
* Enter a stack name
30+
* Enter the desired AWS Region
31+
* Allow SAM CLI to create IAM roles with the required permissions.
32+
33+
Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
34+
35+
1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
36+
37+
## Background
38+
39+
Currently, integration between REST APIs and Application Load Balancers (ALBs) has some limitations. Direct integration is only possible with public ALBs using API Gateway's HTTP integration feature. Private ALBs cannot be directly integrated with API Gateway.
40+
41+
To work around this limitation for private ALBs, a multi-step approach is necessary. First, create an API Gateway VPC link. Then, connect the VPC link to a private Network Load Balancer (NLB). Finally, configure the NLB to forward incoming requests from API Gateway to the private ALB. This setup allows API Gateway to communicate with private ALBs indirectly, enabling the use of private ALBs in API architectures while maintaining the benefits of API Gateway management.
42+
43+
## Prerequisites
44+
45+
1. Active Route 53 Hosted Zone for your domain.
46+
2. Valid ACM (AWS Certificate Manager) certificate that covers the domain managed by your Route 53 Hosted Zone.
47+
48+
## Workaround
49+
50+
1. Use an API Gateway VPC to integrate your API with a private Network Load Balancer.
51+
52+
2. Use the Network Load Balancer to forward the API request to the private Application Load Balancer.
53+
54+
3. Application Load Balancer will forward the traffic to Lambda Function configured on HTTPS listener.
55+
56+
57+
```
58+
Workflow: REST API >> VPC Link >> NLB (TCP listener) >> ALB (HTTPS listener) >> Lambda
59+
```
60+
61+
## Testing
62+
63+
Once the application is deployed, retrieve the API URL provided as output and open it in a browser page.
64+
65+
## Cleanup
66+
67+
1. Delete the stack
68+
```bash
69+
sam delete --stack-name STACK_NAME
70+
```
71+
1. Confirm the stack has been deleted
72+
```bash
73+
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
74+
```
75+
----
76+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
77+
78+
SPDX-License-Identifier: MIT-0
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"title": "REST API Integration with Private ALB integration",
3+
"description": "This pattern explains workaround on how to integrate an API Gateway REST API with an Application Load Balancer.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "AWS SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"To work around this limitation for private ALBs, a multi-step approach is necessary",
11+
"1. Use an API Gateway VPC to integrate your API with a private Network Load Balancer.",
12+
"2. Use the Network Load Balancer to forward the API request to the private Application Load Balancer",
13+
"3. Application Load Balancer will forward the traffic to Lambda Function configured on HTTPS listener."
14+
]
15+
},
16+
"gitHub": {
17+
"template": {
18+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/rest-api-alb-integration-workaround",
19+
"templateURL": "serverless-patterns/rest-api-alb-integration-workaround",
20+
"projectFolder": "rest-api-alb-integration-workaround",
21+
"templateFile": "template.yaml"
22+
}
23+
},
24+
"resources": {
25+
"bullets": [
26+
{
27+
"text": "How do I integrate an API Gateway REST API with an Application Load Balancer",
28+
"link": "https://repost.aws/knowledge-center/api-gateway-application-load-balancers"
29+
}
30+
]
31+
},
32+
"deploy": {
33+
"text": [
34+
"sam deploy"
35+
]
36+
},
37+
"testing": {
38+
"text": [
39+
"Once the application is deployed, retrieve the API URL provided as output and open it in a browser page."
40+
]
41+
},
42+
"cleanup": {
43+
"text": [
44+
"Delete the stack: <code>sam delete</code>."
45+
]
46+
},
47+
"authors": [
48+
{
49+
"name": "Vamsi Pulikonda",
50+
"image": "https://raw.githubusercontent.com/vamsipulikonda/my-photo/main/vamsi-photo.jpg",
51+
"linkedin": "vamsipulikonda",
52+
"bio": "I am a cloud computing enthusiast working as a Cloud Engineer at Amazon Web Services."
53+
}
54+
],
55+
"patternArch": {
56+
"icon1": {
57+
"x": 15,
58+
"y": 50,
59+
"service": "apigw",
60+
"label": "Amazon API Gateway"
61+
},
62+
"icon2": {
63+
"x": 43,
64+
"y": 50,
65+
"service": "alb",
66+
"label": "Network Load Balancer"
67+
},
68+
"icon3": {
69+
"x": 70,
70+
"y": 50,
71+
"service": "alb",
72+
"label": "App. Load Balancer"
73+
},
74+
"icon4": {
75+
"x": 92,
76+
"y": 50,
77+
"service": "lambda",
78+
"label": "AWS Lambda"
79+
},
80+
"line1": {
81+
"from": "icon1",
82+
"to": "icon2"
83+
},
84+
"line2": {
85+
"from": "icon2",
86+
"to": "icon3"
87+
},
88+
"line3": {
89+
"from": "icon3",
90+
"to": "icon4"
91+
}
92+
}
93+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* SPDX-License-Identifier: MIT-0
3+
*/
4+
5+
'use strict'
6+
7+
exports.handler = async (event) => {
8+
// Lambda handler code
9+
console.log(JSON.stringify(event, 0, null))
10+
}

0 commit comments

Comments
 (0)