|
3 | 3 |
|
4 | 4 | ## Description:
|
5 | 5 |
|
6 |
| -This solution creates an [AWS VPC](https://aws.amazon.com/vpc/) environment that has 2 public zones and 2 private zones with an EC2 Target Group that has one EC2 linux instance in it and a [AWS ELB](https://aws.amazon.com/elasticloadbalancing/) (ALB) routing traffic to it. |
| 6 | +This <a href="https://aws.amazon.com/cloudformation/" target="_blank">AWS CloudFormation</a> solution deploys an <a href="https://aws.amazon.com/vpc/" target="_blank">AWS VPC</a> environment that has 2 public zones and 2 private zones with an <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html" target="_blank">EC2 Target Group</a> that has one <a href="https://aws.amazon.com/ec2/" target="_blank">EC2</a> linux instance in it and a <a href="https://aws.amazon.com/elasticloadbalancing/" target="_blank">AWS ELB (ALB)</a> load balancer routing traffic to it. |
7 | 7 |
|
8 | 8 | The AWS CloudFormation template creates a AWS VPC with 2 public subnets and 2 private subnets with an EC2 Target Group that has one EC2 linux instance running Apache on port 80 in it and a public facing ELB (ALB) routing traffic on port 80 to the EC2 target group.
|
9 | 9 |
|
| 10 | +<img src="elb-to-target-group.png" alt="ELB/ALB to EC2 Target Group" /> |
| 11 | + |
10 | 12 | AWS Virtual Private Cloud (Amazon VPC) lets you provision a logically isolated section of the AWS Cloud where you can launch AWS resources in a virtual network that you define.
|
11 | 13 |
|
12 | 14 | AWS Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones.
|
13 | 15 |
|
14 |
| - AWS Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud |
| 16 | +Each AWS Target Group is used to route requests to one or more registered targets. When you create each listener rule, you specify a target group and conditions. When a rule condition is met, traffic is forwarded to the corresponding target group. You can create different target groups for different types of requests. |
| 17 | + |
| 18 | +AWS Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud |
| 19 | + |
| 20 | +AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment. |
| 21 | + |
15 | 22 |
|
16 |
| -_***note AWS ELB and EC2 will incur costs**_ |
| 23 | +## AWS Resource Costs |
17 | 24 |
|
18 |
| -* [ELB pricing](https://aws.amazon.com/elasticloadbalancing/pricing/) resource used in example: 1 Application Load Balancer |
19 |
| -* [EC2 pricing](https://aws.amazon.com/ec2/pricing/on-demand/) resource used in example: 1 t2.nano |
| 25 | +As with most AWS services you will incur costs for usage. For this CloudFormation template the resources that incur costs are as follows. |
20 | 26 |
|
21 |
| -## Prerequisites: |
| 27 | +* Pricing: |
22 | 28 |
|
23 |
| -* AWS account and environment configured with AWS Credentials |
24 |
| -* IAM user with AWSCloudFormationReadOnlyAccess, AmazonVPCFullAccess, AmazonEC2FullAccess |
| 29 | + * <a href="https://aws.amazon.com/elasticloadbalancing/pricing/" target="_blank">ELB Pricing</a> resource used in example: *1 Application Load Balancer* |
| 30 | + * <a href="https://aws.amazon.com/ec2/pricing/on-demand/" target="_blank">EC2 pricing</a> resource used in example: *1 t2.nano* |
| 31 | + |
| 32 | +## Prerequisites |
| 33 | + |
| 34 | +* <a href="https://aws.amazon.com" target="_blank"> Amazon Web Services Account</a> |
| 35 | +* <a href="https://aws.amazon.com/iam/" target="_blank">IAM</a> user with the following permissions: |
| 36 | + * AWSCloudFormationReadOnlyAccess |
| 37 | + * AmazonVPCFullAccess |
| 38 | + * AmazonEC2FullAccess |
| 39 | +* An <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html" target="_blank">EC2 Key Pair</a> in the region you are deploying |
25 | 40 | * This example works without modification in the following regions: us-west-1, us-west-2, us-east-1, us-east-2
|
26 | 41 |
|
27 |
| -## See how it works: |
| 42 | +## CloudFormation Template |
| 43 | + |
| 44 | +* The CloudFormation Template is available on GitHub: |
| 45 | + * <a href="https://github.com/getcft/aws-elb-to-ec2-target-group-cf-template" target="_blank">aws-elb-to-ec2-target-group-cf-template</a> |
| 46 | + |
| 47 | +## Deploy the CloudFormation Template |
28 | 48 |
|
29 |
| -AWS Management Console |
| 49 | +* AWS Management Console |
30 | 50 |
|
31 |
| -* Login to AWS Management Console |
32 |
| -* Launch in CloudFormation elb-to-ec2-target-group-cf-template.yml (from the repo you cloned) |
| 51 | + * Login to *AWS Management Console* |
| 52 | + * Launch under *CloudFormation* your *elb-to-ec2-target-group-cf-template.yml* (included in this repo) |
33 | 53 |
|
34 |
| -CloudFormation Fields |
| 54 | +* CloudFormation Fields: |
35 | 55 |
|
36 |
| -* Stack name (Enter a name to associate to your AWS VPC, ELB, EC2 deployment) |
37 |
| -* SSHKeyName (Used for EC2 Instance) **Next** |
38 |
| -* Continue choosing **Next** |
39 |
| -* Click **Create** |
| 56 | + * *Stack name* (Enter a name to associate to your AWS ELB / Target Group deployment) |
| 57 | + * SSHKeyName (EC2 Key Pair used for EC2 Instance) *Next* |
| 58 | + * Continue choosing *Next* and then *Create* (it may take several mintues to create resources) |
40 | 59 |
|
41 |
| -## Test: |
| 60 | +## Results of the CloudFormation Template |
42 | 61 |
|
43 |
| -In the AWS Management Console you should be able to verify the following have been created: |
| 62 | +In the *AWS Management Console* you should be able to *verify* the following have been created. |
44 | 63 |
|
45 |
| -* 1 Public Subnet 10.0.10.0/24 (Zone A) |
46 |
| -* 1 Private Subnet 10.0.20.0/24 (Zone A) |
47 |
| -* 1 Public Subnet 10.0.30.0/24 (Zone B) |
48 |
| -* 1 Private Subnet 10.0.40.0/24 (Zone B) |
49 |
| -* 5 Route table entries to route either within 10.0.0.0/16 or to the Internet Gateway for outbound |
50 |
| -* 1 Internet Gateway |
51 |
| -* 1 ELB Security Group with Port 80 open to everyone |
52 |
| -* 1 EC2 Security Group with Port 22 open to everyone and Port 80 open to the Load Balancer |
53 |
| -* 1 ELB Application Load Balancer |
54 |
| -* 1 EC2 t2.nano linux instance running Apache |
55 |
| -* 1 EC2 Target Group |
| 64 | +* Resources Created: |
| 65 | + * 1 Public Subnet 10.0.10.0/24 (in Zone A, with 254 usable IP's) |
| 66 | + * 1 Private Subnet 10.0.20.0/24 (in Zone A, with 254 usable IP's) |
| 67 | + * 1 Public Subnet 10.0.30.0/24 (in Zone B, with 254 usable IP's) |
| 68 | + * 1 Private Subnet 10.0.40.0/24 (in Zone B, with 254 usable IP's) |
| 69 | + * 5 Route table entries to route traffic either within 10.0.0.0/16 or to the Internet Gateway for outbound |
| 70 | + * 1 Internet Gateway (for all outbound traffic) |
| 71 | + * 1 ELB Security Group with Port 80 open to everyone |
| 72 | + * 1 EC2 Security Group with Port 22 open to everyone and Port 80 open to the Load Balancer |
| 73 | + * 1 ELB Application Load Balancer |
| 74 | + * 1 EC2 t2.nano linux instance running Apache |
| 75 | + * 1 EC2 Target Group |
56 | 76 |
|
57 | 77 | You can find in the CloudFormation Outputs section the "ALBHostName" copy the hostname from the "Value" column and paste it into a browser you should see the word "Healthy" return.
|
58 | 78 |
|
59 |
| -## Other Things: |
| 79 | +## Best Practices |
60 | 80 |
|
61 | 81 | * You would normally put your EC2 instance or instances in a private subnet but to save costs for this example we didn't provision a NAT Gateway but needed to install Apache so we elected to put it in a public subnet.
|
| 82 | +* For traffic that does not need to be reachable from outside your VPC private network space you can provision ELB to be internal versus this example where ELB is public internet facing. |
0 commit comments