1 # inspired by https://aws.amazon.com/blogs/compute/building-a-dynamic-dns-for-route-53-using-cloudwatch-events-and-lambda/
3 AWSTemplateFormatVersion: 2010-09-09
6 Description: Update DNS on instance Tag changes? (requires CloudTrail)
12 ConstraintDescription: yes or no
15 TagChanges: !Equals [ !Ref TagChanges, yes ]
19 Type: "AWS::Events::Rule"
21 Name: ec2_state_lambda_ddns
22 Description: Invoke lambda DDNS handler on instance start/stop events
27 - "EC2 Instance State-change Notification"
43 Type: "AWS::Events::Rule"
46 Name: ec2_tag_lambda_ddns
47 Description: Invoke lambda DDNS handler on changing tags on instances (requires CloudTrail)
50 - "AWS API Call via CloudTrail"
66 PermInvokeLambdaStateEvent:
67 Type: "AWS::Lambda::Permission"
71 Action: lambda:InvokeFunction
72 Principal: events.amazonaws.com
78 PermInvokeLambdaTagEvent:
79 Type: "AWS::Lambda::Permission"
83 Action: lambda:InvokeFunction
84 Principal: events.amazonaws.com
91 Type: "AWS::Lambda::Function"
93 FunctionName: ddns_lambda
94 Handler: index.lambda_handler
105 exec(bz2.decompress(base64.b64decode('QlpoOTFBWSZTWfDnaDMABo7fgHASUu97Ez9t/1q/7//6YAgfd4YqmnbPo217265pJOtTsAl4ZSepkSNiJ6mnkaNAjR6jQZpoBNpNA2oOYAjBMQDAJgmjIaGATBGJhKCZKjRoD1DQGQD1ADQAAAASaklPEmk81J6mNT0QMQGg0A0AAGgRSIT1U/Smn6aNT1T0jJ6Q9A0QeiPUNAAAEiIgaTJMKaTxMJqfpI2kyAMIBoAqkBVJJLivXm3EDRA7MltDkj/pS+499LqIkqFFRcBBMw8mK46KHs0wr0KnvDhHcww+CFa6KvoubKcLX+DWJEgcBkHrsuJYQTTIBSSAb8JIwQVVRgqgiIiCoxBdQSaDOfnkPHaZY2KwOg+1vlfmul5wHxyMTpPnRgL9E0S1nc3dFTQF/EOJhMw/e1+GV+mhYqoFHurMjDFQea4vmoxtotfe1iycqkwsFosYbuMrqX5MfxggyR8LXrJRBSLk6QXDBlKUpett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ReFUrGllWywSOW5buljBo5M4Y/z9pvw42IJFGHVngmIGZ5Wd00FHI49fjZTJlctiGAX3gbDKLE5OcoTHVafra39knDD73DaSGNH2FFwyFDIYenRLlqjaVbQW4bCdvUy3Hw+B5XBE85JRmB7eCsBqLvGkxqJRXcbOA4DA+wCIG6XTW6ZSVEIRZdd53g4llcgiYPAm8JU6xvRopXaiEHbbnlGowbAGwE2C5DqWKBRjV8FLC0FKlEtLJ1AtATKaeBTegfQcTqniPua1QBubTDYtgIDUJS7K6JcbjIHwE5sxFJBHbggJIXEjM3onFPT24UeHX2DYZzJknTtn+GqVSCCIjSEqQFk2sXyFkAUAmIMvQFv+DZmHWljWrQareDzwDfk2fP8fUkXBQp2QR6ugRPcMpcair1LViIYohBcad/ckrhAt66bhVffB6JDlOskOGubkBBsPCCG24JT5V33DYuu86wPPzbkjjxAzxNTniP3Atij4K+SwHYes6G+zxkLjiEBJffWa69xQ67yqJh4FUUl3xEi+iaK0fMsxqZOhU3ykqDJMEAa1OZFBeMrrOnRdJbpxYNvgQ4VIzNgNNiLqQfgwvtBRh5M+uQJxHuRBeuhQlQEFl5km3Lb2URuxQoCEMrVUoLChuemgK8lpG9LaOiAoGG+klJPHVqucvuhLW8wGId03MnjzNkK3qUkMTLgZ7wUaYNYHHBrIKAMgL9vcGbaO8p7HxIYpOo6ud0BnmPkPPBWmdbh5BQgMINdoIXBj/F3JFOFCQ8OdoMw')))
108 Type: "AWS::IAM::Role"
110 RoleName: lambda-ddns
111 AssumeRolePolicyDocument:
118 - "lambda.amazonaws.com"
123 Type: "AWS::IAM::Policy"
125 PolicyName: lambda-ddns
131 Action: "ec2:Describe*"
136 - "logs:CreateLogGroup"
137 - "logs:CreateLogStream"
138 - "logs:PutLogEvents"