8000 Update README.md · dacdo/aws-lambda-ddns-function@da953d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit da953d8

Browse files
committed
Update README.md
1 parent f32a735 commit da953d8

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
##Introduction
44

5-
Dynamic registration of resource records is useful when you have instances that are not behind a load balancer that you would like address by a host name and domain suffix of your choosing rather than the default \<region\>.compute.internal or ec2.internal.
5+
Dynamic registration of resource records is useful when you have instances that are not behind a load balancer and that you would like address by a host name and domain suffix of your choosing rather than the default \<region\>.compute.internal or ec2.internal assigned by VPC DNS.
66

7-
In this project we explore how you can use [CloudWatch Events](https://aws.amazon.com/cloudwatch) and Lambda to create a Dynamic DNS for Route 53. Besides creating A records, this project lets you to create alias, i.e. CNAME records, for when you want to address a server by a "friendly" or alternate name. Although this is antithetical to treating instances as disposable resources, there are still a lot of shops that find this useful.
7+
In this project we explore how you can use [CloudWatch Events](https://aws.amazon.com/cloudwatch) and Lambda to create a Dynamic DNS for Route 53. Besides creating A records, this project allows you to create alias, i.e. CNAME records, for when you want to address a server by a "friendly" or alternate name. Although this is antithetical to treating instances as disposable resources, there are still a lot of shops that find this useful.
88

99
##Using CloudWatch and Lambda to respond to infrastructure changes in real-time
1010

@@ -18,7 +18,7 @@ The example provided in this project works precisely this way. It uses informat
1818

1919
Route 53 offers the convenience of domain name services without having to build a globally distributed highly reliable DNS infrastructure. It allows instances within your VPC to resolve the names of resources that run within your AWS environment. It also lets clients on the Internet resolve names of your public-facing resources. This is accomplished by querying resource record sets that reside within a Route 53 public or private hosted zone.
2020

21-
A private hosted zone is basically a container that holds information about how you want to route traffic for a domain and its subdomains within one or more VPC whereas a public hosted zone is a container that holds information about how you want to route traffic from the Internet.
21+
A private hosted zone is basically a container that holds information about how you want to route traffic for a domain and its subdomains within one or more VPCs whereas a public hosted zone is a container that holds information about how you want to route traffic from the Internet.
2222

2323
##Choosing between VPC DNS or Route 53 Private Hosted Zones
2424

@@ -28,11 +28,9 @@ Unless you create a DHCP option set with a custom domain name and disable hostna
2828

2929
Private hosted zones help you overcome these challenges by allowing you to create different resource record types with a custom domain suffix. Moreover, with Route 53 you can create a subdomain for your current DNS namespace or you can migrate an existing subdomain to Route 53. By using these options, you can create a contiguous DNS namespace between your on-premises environment and AWS.
3030

31-
So while VPC DNS can provide basic name resolution for your VPC, Route 53 private hosted zones offer richer functionality by comparison. It also has a programmable API that can be used to automate the creation/removal of records sets and hosted zones which we’re going leverage extensively in this project.
31+
So, while VPC DNS can provide basic name resolution for your VPC, Route 53 private hosted zones offer richer functionality by comparison. It also has a programmable API that can be used to automate the creation/removal of records sets and hosted zones which we’re going leverage extensively in this project.
3232

33-
##Use case
34-
35-
Route 53 doesn't offer support for dynamic registration of resource record sets for public or private hosted zones. This can pose challenges when an automatic scaling event occurs and the instances are not behind a load balancer. A common workaround is to use an automation framework like Chef, Puppet, Ansible, or Salt to create resource records, or by adding instance user data to the launch profile of the Auto Scaling group. The drawbacks to these approaches is that:
33+
Route 53 doesn't offer support for dynamic registration of resource record sets for public or private hosted zones. This can pose challenges when an automatic scaling event occurs and the instances are not behind a load balancer. A common workaround is to use an automation framework like Chef, Puppet, Ansible, or Salt to create resource records, or by adding instance user data to the launch profile of the Auto Scaling group. The drawbacks to these approaches are that:
3634

3735
1. automation frameworks typically require you to manage additional infrastructure.
3836
2. instance user data doesn't handle the removal of resource records when the instance is terminated.
@@ -43,19 +41,19 @@ This was the motivation for creating a serverless architecture that dynamically
4341

4442
Make sure that you have the latest version of the AWS CLI installed locally. For more information, see [Getting Set Up with the AWS Command Line Interface](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html).
4543

46-
For this example, create a new VPC configured with a private and public subnet, using [Scenario 2: VPC with Public and Private Subnets (NAT)](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html) from the Amazon VPC User Guide. Ensure that the VPC has the DNS resolution and DNS hostnames options set to yes.
44+
For this example, create a new VPC configured with a private and public subnet, using [Scenario 2: VPC with Public and Private Subnets (NAT)](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario2.html) from the Amazon VPC User Guide. Ensure that the VPC has the **DNS resoluti 8000 on** and **DNS hostnames** options set to **yes**.
4745

4846
After the VPC is created, you can proceed to the next steps.
4947

5048
#####Step 1 – Create an IAM role for the Lambda function
5149

52-
In this step, you use the AWS Command Line Interface (AWS CLI) to create the Identity and Access Management (IAM) role that the Lambda function assumes when the function is invoked. You need to create an IAM policy with the required permissions and then attach this policy to the role.
50+
In this step, you will use the AWS Command Line Interface (AWS CLI) to create the Identity and Access Management (IAM) role that the Lambda function assumes when the function is invoked. You also need to create an IAM policy with the required permissions and then attach this policy to the role.
5351

5452
1) Download the **ddns-policy.json** and **ddns-trust.json** files from the [AWS Labs GitHub repo](https://github.com/awslabs/aws-lambda-ddns-function).
5553

5654
_ddns-policy.json_
5755

58-
The policy includes **ec2:Describe permission**, required for the function to obtain the EC2 instance’s attributes, including the private IP address, public IP address, and DNS hostname. The policy also includes DynamoDB and Route 53 full access, required for the function to create the DynamoDB table and to update the Route 53 DNS records. The policy also allows the function to create log groups and log events.
56+
The policy includes **ec2:Describe permission**, required for the function to obtain the EC2 instance’s attributes, including the private IP address, public IP address, and DNS hostname. The policy also includes DynamoDB and Route 53 full access which the function uses to create the DynamoDB table and update the Route 53 DNS records. The policy also allows the function to create log groups and log events.
5957
```JSON
6058
{
6159
"Version": "2012-10-17",
@@ -106,11 +104,11 @@ The **ddns-trust.json** file contains the trust policy that grants the Lambda se
106104
]
107105
}
108106
```
109-
2) Create the policy using the policy document in the **ddns-pol.json** file. You need to replace **\<LOCAL PATH\>** with your local path to the ** 8000 ddns-pol.json** file. The output of the **aws iam create-policy** command includes the Amazon Resource Locator (ARN). Save the ARN as you need it for future steps.
107+
2) Create the policy using the policy document in the **ddns-pol.json** file. You need to replace **\<LOCAL PATH\>** with your local path to the **ddns-pol.json** file. The output of the **aws iam create-policy** command includes the Amazon Resource Locator (ARN). Save the ARN since you will need it for future steps.
110108
```
111109
aws iam create-policy --policy-name ddns-lambda-policy --policy-document file://<LOCAL PATH>/ddns-pol.json
112110
```
113-
3) Create the **ddns-lambda-role IAM role** using the trust policy in the **ddns-trust.json** file. You need to replace **\<LOCAL PATH\>** with your local path to the **ddns-trust.json** file. The output of the **aws iam create-role** command includes the ARN associated with the role that you created. Save this ARN as you need it when you create the Lambda function in the next section.
111+
3) Create the **ddns-lambda-role IAM role** using the trust policy in the **ddns-trust.json** file. You need to replace **\<LOCAL PATH\>** with your local path to the **ddns-trust.json** file. The output of the **aws iam create-role** command includes the ARN associated with the role that you created. Save this ARN since you will need it when you create the Lambda function in the next section.
114112
```
115113
aws iam create-role --role-name ddns-lambda-role --assume-role-policy-document file://<LOCAL PATH>/ddns-trust.json
116114
```
@@ -120,7 +118,7 @@ aws iam attach-role-policy --role-name ddns-lambda-role --policy-arn <enter-your
120118
```
121119
#####Step 2 – Create the Lambda function
122120

123-
The Lambda function uses modules included in the Python 2.7 Standard Library and the AWS SDK for Python module (boto3), which is preinstalled as part of the Lambda service. As such, you do not need to create a deployment package for this example.
121+
The Lambda function uses modules included in the Python 2.7 Standard Library and the AWS SDK for Python module (boto3), which is preinstalled as part of the Lambda service. As such, you do not need to create a deployment package for this function.
124122

125123
- The function first checks if the “DDNS” table exists in DynamoDB and creates the table if it does not. The table is used to keep a record of instances that have been created, along with their attributes. It is necessary to do this because after an EC2 instance is terminated, its attributes are no longer available, so they must be fetched from the table.
126124

@@ -138,19 +136,19 @@ Use the AWS CLI to create the Lambda function:
138136

139137
1) Download the **union.py.zip** file from the [AWS Labs GitHub repo](https://github.com/awslabs/aws-lambda-ddns-function).
140138

141-
2) Execute the following command to create the function. Note that you need to update the command to use the ARN of the role that you created earlier, as well as the local path to the union.py.zip file containing the Python code for the Lambda function.
139+
2) Execute the following command to create the function. Note that you will need to update the command to use the ARN of the role that you created earlier, as well as the local path to the union.py.zip file containing the Python code for the Lambda function.
142140
```
143141
aws lambda create-function --function-name ddns_lambda --runtime python2.7 --role <enter-your-role-arn-here> --handler union.lambda_handler --timeout 30 --zip-file fileb://<LOCAL PATH>/union.py.zip
144142
```
145-
3) The output of the command returns the ARN of the newly-created function. Save this ARN, as you need it in the next section.
143+
3) The output of the command returns the ARN of the newly-created function. Save this ARN, since you will need it in the next section.
146144

147145
#####Step 3 – Create the CloudWatch Events Rule
148146

149147
In this step, you create the CloudWatch Events rule that triggers the Lambda function whenever CloudWatch detects a change to the state of an EC2 instance. You configure the rule to fire when any EC2 instance state changes to “running”, “shutting down”, or “stopped”. Use the **aws events put-rule** command to create the rule and set the Lambda function as the execution target:
150148
```
151149
aws events put-rule --event-pattern "{\"source\":[\"aws.ec2\"],\"detail-type\":[\"EC2 Instance State-change Notification\"],\"detail\":{\"state\":[\"running\",\"shutting-down\",\"stopped\"]}}" --state ENABLED --name ec2_lambda_ddns_rule
152150
```
153-
The output of the command returns the ARN to the newly created CloudWatch Events rule, named **ec2\_lambda\_ddns\_rule**. Save the ARN, as you need it to associate the rule with the Lambda function and to set the appropriate Lambda permissions.
151+
The output of the command returns the ARN to the newly created CloudWatch Events rule, named **ec2\_lambda\_ddns\_rule**. Save the ARN, as you will need it to associate the rule with the Lambda function and to set the appropriate Lambda permissions.
154152

155153
Next, set the target of the rule to the Lambda function. Note that the **--targets** input parameter requires that you include a unique identifier for the **Id** target. You also need to update the command to use the ARN of the Lambda function that you created previously.
156154
```

0 commit comments

Comments
 (0)
0