Skip to content

Commit ff14c65

Browse files
authored
Merge pull request #2438 from biswanathmukherjee/biswanathmukherjee-feature-r53-alb-s3
New Serverless Pattern - Route53-ALB-S3 (hosting a private website)
2 parents e43db15 + 1e848ba commit ff14c65

File tree

6 files changed

+657
-0
lines changed

6 files changed

+657
-0
lines changed

route53-alb-s3/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Internal static website hosting using Amazon Route53, Application Load Balancer and Amazon S3
2+
3+
This pattern deploys a framework to host an internal static website on Amazon S3 bucket that can only be accessed from private network.
4+
5+
Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns/route53-alb-s3](https://serverlessland.com/patterns/route53-alb-s3)
6+
7+
**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.
8+
9+
## Requirements
10+
11+
* [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.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
16+
## Deployment Instructions
17+
18+
1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
19+
```
20+
sam deploy --guided
21+
```
22+
2. During the prompts:
23+
* Enter a stack name
24+
* Enter the desired AWS Region e.g. us-east-1
25+
* Enter PrivateWebsiteDomainName e.g. hello-world.example.com
26+
* Allow SAM CLI to create IAM roles with the required permissions
27+
* Leave all other options to default values
28+
29+
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.
30+
31+
3. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
32+
33+
4. From the command line, run the below command to upload the `index.html` to the S3 bucket. Replace `{WebsiteBucket}` with the corresponding output value of the `sam deploy` command.
34+
```
35+
aws s3 cp index.html s3://{WebsiteBucket}
36+
```
37+
38+
## How it works
39+
40+
Please refer to the architecture diagram below:
41+
42+
![End to End Architecture](architecture.png)
43+
44+
This template deploys a Route53 hosted zone, an Application Load Balancer (ALB), a VPC Endpoint and a S3 bucket. The private website URL will be exposed via the Route 53 private hosted zone. This URL is accessible from within the VPC.
45+
46+
## Testing
47+
48+
1. [Create a CloudShell VPC environment](https://docs.aws.amazon.com/cloudshell/latest/userguide/creating-vpc-environment.html). Enter the following values:
49+
* Name - enter your preferred environment name.
50+
* VPC - `VPCId` from the `sam deploy` output.
51+
* Subnet - Select any of the two available subnets under the above VPC.
52+
* Security - `ALBSecurityGroup` from the `sam deploy` output.
53+
54+
2. From the CloudShell command prompt run the following command to access your private website. Replace `{PrivateWebsiteUrl}` with the corresponding output value of the `sam deploy` command:
55+
```
56+
curl -k -L {PrivateWebsiteUrl}
57+
```
58+
- The `curl` command makes an HTTP GET request to the deployed private website.
59+
- `-k` option allows curl to ignore that the certificate is issued by a private certificate authority and proceed with making the invocation.
60+
- `-L` option tells curl to follow any HTTP redirects that the server sends. If the server responds with a 3xx HTTP status code and provides a new URL, curl will automatically issue a new request to the new URL.
61+
62+
3. You can also test by spinning up an EC2 instance within the same VPC or from another location that has private connectivity to the VPC. However, if you try to access the URL from outside network, it will not be reachable.
63+
64+
## Cleanup
65+
66+
1. Delete the contents of the S3 bucket. Make sure to use the correct bucket name.
67+
```bash
68+
aws s3 rm s3://{WebsiteBucket} --recursive
69+
```
70+
2. Delete the CloudShell environment created in the VPC.
71+
3. Delete the stack
72+
```bash
73+
sam delete
74+
```
75+
76+
----
77+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
78+
79+
SPDX-License-Identifier: MIT-0

route53-alb-s3/architecture.png

21.2 KB
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"title": "Internal static website hosting using Amazon Route53, ALB and Amazon S3",
3+
"description": "This pattern hosts an internal static website on an Amazon S3 bucket that can only be accessed from private network.",
4+
"language": "YAML",
5+
"level": "200",
6+
"framework": "SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This template deploys a Route53 hosted zone, an Application Load Balancer (ALB), a VPC Endpoint and a S3 bucket.",
11+
"The private website URL will be exposed via the Route 53 private hosted zone. This URL is accessible from within the VPC."
12+
]
13+
},
14+
"gitHub": {
15+
"template": {
16+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/route53-alb-s3",
17+
"templateURL": "serverless-patterns/route53-alb-s3",
18+
"projectFolder": "route53-alb-s3",
19+
"templateFile": "template.yaml"
20+
}
21+
},
22+
"resources": {
23+
"bullets": [
24+
{
25+
"text": "Hosting Internal HTTPS Static Websites with ALB, S3, and PrivateLink",
26+
"link": "https://aws.amazon.com/blogs/networking-and-content-delivery/hosting-internal-https-static-websites-with-alb-s3-and-privatelink/"
27+
},
28+
{
29+
"text": "AWS PrivateLink for Amazon S3",
30+
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html"
31+
}
32+
]
33+
},
34+
"deploy": {
35+
"text": [
36+
"sam build",
37+
"sam deploy --guided"
38+
]
39+
},
40+
"testing": {
41+
"text": [
42+
"See the GitHub repo for detailed testing instructions."
43+
]
44+
},
45+
"cleanup": {
46+
"text": [
47+
"Delete the content of the S3 bucket: <code>aws s3 rm s3://{WebsiteBucket} --recursive</code>",
48+
"Delete the stack: <code>sam delete</code>.",
49+
"Delete the newly created CloudShell environment."
50+
]
51+
},
52+
"authors": [
53+
{
54+
"name": "Biswanath Mukherjee",
55+
"image": "https://d1rwvjey2iif32.cloudfront.net",
56+
"bio": "I am a Sr. Solutions Architect working at AWS India.",
57+
"linkedin": "biswanathmukherjee"
58+
},
59+
{
60+
"name": "Rakshith Rao",
61+
"image": "https://rao.sh/assets/img/profile_pic.png",
62+
"bio": "I am a Senior Solutions Architect at AWS and help our strategic customers build and operate their key workloads on AWS.",
63+
"linkedin": "rakshithrao"
64+
}
65+
]
66+
}

route53-alb-s3/index.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Sample Website</title>
6+
<style>
7+
body {
8+
color: #ffffff;
9+
background-color: #0188cc;
10+
font-family: Arial, sans-serif;
11+
font-size: 14px;
12+
}
13+
14+
h1 {
15+
font-size: 500%;
16+
font-weight: normal;
17+
margin-bottom: 0;
18+
}
19+
20+
h2 {
21+
font-size: 200%;
22+
font-weight: normal;
23+
margin-bottom: 0;
24+
}
25+
</style>
26+
</head>
27+
<body>
28+
<div align="center">
29+
<h1>Hello World!</h1>
30+
</div>
31+
</body>
32+
</html>
33+

route53-alb-s3/route53-alb-s3.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"title": "Internal static website hosting using Amazon Route53, ALB and Amazon S3",
3+
"description": "This pattern hosts an internal static website on an Amazon S3 bucket that can only be accessed from private network.",
4+
"language": "YAML",
5+
"level": "200",
6+
"framework": "SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This template deploys a Route53 hosted zone, an Application Load Balancer (ALB), a VPC Endpoint and a S3 bucket.",
11+
"The private website URL will be exposed via the Route 53 private hosted zone. This URL is accessible from within the VPC."
12+
]
13+
},
14+
"gitHub": {
15+
"template": {
16+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/route53-alb-s3",
17+
"templateURL": "serverless-patterns/route53-alb-s3",
18+
"projectFolder": "route53-alb-s3",
19+
"templateFile": "template.yaml"
20+
}
21+
},
22+
"resources": {
23+
"bullets": [
24+
{
25+
"text": "Hosting Internal HTTPS Static Websites with ALB, S3, and PrivateLink",
26+
"link": "https://aws.amazon.com/blogs/networking-and-content-delivery/hosting-internal-https-static-websites-with-alb-s3-and-privatelink/"
27+
},
28+
{
29+
"text": "AWS PrivateLink for Amazon S3",
30+
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html"
31+
}
32+
]
33+
},
34+
"deploy": {
35+
"text": [
36+
"sam build",
37+
"sam deploy --guided"
38+
]
39+
},
40+
"testing": {
41+
"text": [
42+
"See the GitHub repo for detailed testing instructions."
43+
]
44+
},
45+
"cleanup": {
46+
"text": [
47+
"Delete the content of the S3 bucket: <code>aws s3 rm s3://{WebsiteBucket} --recursive</code>",
48+
"Delete the stack: <code>sam delete</code>.",
49+
"Delete the newly created CloudShell environment."
50+
]
51+
},
52+
"authors": [
53+
{
54+
"name": "Biswanath Mukherjee",
55+
"image": "https://d1rwvjey2iif32.cloudfront.net",
56+
"bio": "I am a Sr. Solutions Architect working at AWS India.",
57+
"linkedin": "biswanathmukherjee"
58+
},
59+
{
60+
"name": "Rakshith Rao",
61+
"image": "https://rao.sh/assets/img/profile_pic.png",
62+
"bio": "I am a Senior Solutions Architect at AWS and help our strategic customers build and operate their key workloads on AWS.",
63+
"linkedin": "rakshithrao"
64+
}
65+
],
66+
"patternArch": {
67+
"icon1": {
68+
"x": 20,
69+
"y": 50,
70+
"service": "route53",
71+
"label": "Route 53"
72+
},
73+
"icon2": {
74+
"x": 50,
75+
"y": 50,
76+
"service": "alb",
77+
"label": "Application Load Balancer"
78+
},
79+
"icon3": {
80+
"x": 80,
81+
"y": 50,
82+
"service": "s3",
83+
"label": "S3 bucket"
84+
},
85+
"line1": {
86+
"from": "icon1",
87+
"to": "icon2",
88+
"label": ""
89+
},
90+
"line2": {
91+
"from": "icon2",
92+
"to": "icon3",
93+
"label": ""
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)