You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
122
122
123
-
-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. This is necessary because once an EC2 instance is terminated, its attributes are no longer available to be queried. Instead, they must be fetched from the table.
123
+
The function code performs the following:
124
124
125
-
- The function then queries the event data to determine the instance's state. If the state is “running”, the function queries the EC2 API for the data it will need to update DNS. If the state is anything else, e.g. "stopped" or "terminated", it will retrieve the necessary information from the “DDNS” DynamoDB table.
125
+
- Checks to see whether the “DDNS” table exists in DynamoDB and creates the table if it does not. This table is used to keep a record of instances that have been created along with their attributes. It’s necessary to persist the instance attributes in a table because once an EC2 instance is terminated, its attributes are no longer available to be queried via the EC2 API. Instead, they must be fetched from the table.
126
126
127
-
The function also checks whether “DNS resolution” and “DNS hostnames” are enabled since both are required in order to use Route 53 for private name resolution. It then checks to see whether a private hosted zone for the instance exists. If it does, it will proceed to check whether a private hosted zone is associated with the instance's VPC. If no such association exists, the function will create the association. Like DNS resolution and DNS hostname, this VPC/private-hosted-zone association is necessary in order for the VPC to Route 53 for DNS resolution.
127
+
- Queries the event data to determine the instance's state. If the state is “running”, the function queries the EC2 API for the data it will need to update DNS. If the state is anything else, e.g. "stopped" or "terminated", it will retrieve the necessary information from the “DDNS” DynamoDB table.
128
128
129
-
- Next, the function checks the EC2 instance’s tags for the CNAME and ZONE tags. If the ZONE tag is found, the function creates A and PTR records in the specified zone. If the CNAME tag is found, the function creates a CNAME record in the specified zone.
129
+
- Verifies that “DNS resolution” and “DNS hostnames” are enabled for the VPC, as these are required in order to use Route 53 for private name resolution. The function then checks whether a reverse lookup zone for the instance already exists. If it does, it checks to see whether the reverse lookup zone is associated with the instance's VPC. If it isn't, it creates the association. This association is necessary in order for the VPC to use Route 53 zone for private name resolution.
130
130
131
-
Next, the function checks to see whether there's a DHCP option set assigned to the VPC. If there is, it uses the value of the domain name to create resource records in the appropriate Route 53 private hosted zone. The function also checks to see whether there's an association between the instance's VPC and the private hosted zone for reverse lookups. If there isn't, it creates it.
131
+
- Checks the EC2 instance’s tags for the CNAME and ZONE tags. If the ZONE tag is found, the function creates A and PTR records in the specified zone. If the CNAME tag is found, the function creates a CNAME record in the specified zone.
132
132
133
-
- The function deletes the required DNS resource records if the state of the EC2 instance changes to “shutting down” or “stopped”.
133
+
- Verifies whether there's a DHCP option set assigned to the VPC. If there is, it uses the value of the domain name to create resource records in the appropriate Route 53 private hosted zone. The function also checks to see whether there's an association between the instance's VPC and the private hosted zone. If there isn't, it creates it.
134
+
135
+
- Deletes the required DNS resource records if the state of the EC2 instance changes to “shutting down” or “stopped”.
0 commit comments