GithubHelp home page GithubHelp logo

aws-lambdas's Introduction

AWS Lambdas

Topics


CloudFormation Integrations

Custom Resources

For information about custom resources, refer to the Documentation.


Custom Resource Handler

Base class for lambda backend for CloudFormation custom resources provides methods for parsing the event object, sending a response to cloudformation, and returning a well formed response. An overridable method execute, which can be implemented by derived classes performs the Operation on a list of Operands. A dictionary operations used as a registry of Operator to function mappings used by this handler.

Given the following template:

Parameters:
  MyCustomResourceFunction:
    Description: Custom resource handler function Arn
    Type: AWS::SSM::Parameter::Value<String>
    Default: /MyCommonFunctions/MyCustomResourceFunction

Resources:
  MyEcho:
    Type: Custom::Echo
    Properties:
      ServiceToken: !Ref MyCustomResourceFunction
      Operator: echo
      Operands:
        - this is a
        - test

Outputs:
  Echo:
    Description: The output of the custom resource
    Value: !GetAtt MyEcho.Value

The following will be included in the lambda event:

{
    'ResponseURL': 'http://pre-signed-S3-url-for-response',
    'StackId' : 'arn:aws:cloudformation:us-west-2:123456789012:stack/stack-name/guid',
    'RequestId' : 'unique id for this create request',
    'ResourceType' : 'Custom::Echo',
    'LogicalResourceId' : 'MyEcho',
    'ResourceProperties': {
        'Operator': 'echo',
        'Operands': ['this is a', 'test']
    }
}

The Data response data of the execute method is put into a dictionary as a string:

{
    'Value': str(operations[operator](operands))
}

The Status is captured as a string 'SUCCESS' | 'FAILED'.

The following payload will be sent to the ResponseUrl for cloudformation:

{
{
    'Status': 'SUCCESS' or 'FAILED',
    'LogStream': context.log_stream_name,
    "PhysicalResourceId": pysical_resource_id or context.log_stream_name,
    'StackId': event['StackId'],
    'RequestId': event['RequestId'],
    'LogicalResourceId': event['LogicalResourceId'],
    'NoEcho': True | False,
    'Data': data
}
}

The following responses are returned by the handler.

Success response:

{
    statusCode: 200,
    body: <json data>
}

Failed response:

{
    statusCode: 400,
    body: <json data with the exception>
}

Basic Calculator Handler

Lambda backend for CloudFormation custom resources providing basic calculator functions.

Operations:

  • /
  • %

Operands:

  • Number(s)

Network Calculator Handler

Lambda backend for CloudFormation custom resources that do networking related caclulations like the subnet size in bits of a given network cidr for a specific number of subnets.

Operations:

  • SubnetSize

Operands:

  • CIDR
  • Number of subnets

aws-lambdas's People

Contributors

dependabot[bot] avatar jg75 avatar

Watchers

 avatar  avatar

aws-lambdas's Issues

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.