Giter VIP home page Giter VIP logo

autoscaling-route53-lambda's Introduction

autoscaling-route53-lambda

This code can be used to manage Route53 records of type CNAME or A for an Autoscaling Group with Lambda via a tag on the ASG. The main function listens for TERMINATE and LAUNCH events, and DELETEs and UPSERTs records to Route53.

Usage

Create an Autoscaling Group Tag called 'Route53' with values in any of these formats:

    • Tag Name: 'Route53' (defined in tagName variable)
    • Tag value:
  •   1) 'HostedZoneId:record-name'                       Ex. Z1473BHDWSM6GV:www.example.com              (assumes CNAME type and TTL of 1)
    
  •   2) 'HostedZoneId:type:record-name'                  Ex. Z1473BHDWSM6GV:CNAME:www.example.com        (assumes TTL of 1)'
    
  •   3) 'HostedZoneId:type:record-name:ttl'              Ex. Z1473BHDWSM6GV:CNAME:www.example.com:30)'
    
  •   4) <empty string> or value of 'none' is ignored
    

ZIP it up

Create ZIP file with zip ../autoscaling-route53.js index.js async

Install (for lack of better words)

AWS makes this relatively easy for you, but you still have to jump some hoops. Let's use the Console for this, as it is easiest.

For a given Autoscaling Group you want to 'sync' with Route53, do the following:

  1. create an IAM role with policies AmazonEC2ReadOnlyAccess, CloudWatchLogsFullAccess and AmazonRoute53FullAccess (our name is AutoscalingRoute53Role)
  2. create a Lambda function with ZIP and IAM Role from before (our name is autoscalingRoute53)
  3. create an SNS topic (our topic name asg-notifications-staging-elasticsearch-30mhz-com)
  4. add a subscription to SNS topic, pointing to the Lambda function
  5. on the notifications tab in the details pane of the Autoscaling Group, you click 'Create notification'
  6. set 'send notification to' to the SNS topic
  7. and only 'launch' and 'terminate' are used by this lambda function. Other messages are ignored.
  8. last, but not least, add a tag to the Autoscaling Group with key 'Route53' and value 'HostedZoneId:record-name'

And now, scale :)

Using Cloudformation

If you want to script this setup with Cloudformation, here is a snippet that covers steps 3 - 7 above. This snippet would be put into the 'Resources' of a Cloudformation script.

"Resources": {

  ....

    "LambdaDNS": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "FunctionName" : "asg-to-dns-v1",
            "Code": {
                "S3Bucket": "bionano-devops-build-artifacts",
                "S3Key": "lambdas/lambdaDNS/autoscaling-route53.js.zip"
            },
            "Description" : "Lambda to update dns based on asg events", 
            "Role": { "Fn::Join" : [ "/", [ "arn:aws:iam::123456789012:role", "lambda-asg-sns-dns"] ] },
            "Timeout": 60,
            "Handler": "index.handler",
            "Runtime": "nodejs4.3",
            "MemorySize": 128
        }
    },

    "autoscalingNotificationTopic" : {
      "Type" : "AWS::SNS::Topic",
      "DependsOn" : [ "LambdaDNS" ], 
      "Condition": "IsUSWest2",
      "Properties" : {
        "DisplayName" : "wD Scaling",
        "Subscription" : [ 
            { "Endpoint"  : {"Fn::GetAtt" : [ "LambdaDNS", "Arn" ]}, "Protocol"  : "lambda" }
        ],
       "TopicName" : "dev-autoscaling-NotificationTopic"
      }
    },      

    "LambdaInvokePermission": {
        "Type": "AWS::Lambda::Permission",
        "Condition": "IsUSWest2",
        "DependsOn" : [ "LambdaDNS", "autoscalingNotificationTopic" ], 
        "Properties": {
          "Action": "lambda:InvokeFunction",
          "Principal": "sns.amazonaws.com",
          "SourceArn": { "Ref": "autoscalingNotificationTopic" },
          "FunctionName": { "Fn::GetAtt": [ "LambdaDNS", "Arn" ] }
        }
    }
  .....

autoscaling-route53-lambda's People

Contributors

peterrjones avatar truthtrap avatar

Stargazers

Jack Warner avatar Drew Hylbert avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.