cfn

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Overview

CloudFormation has a different way of responding to most events due to the way stacks execute.

It is best to catch all errors and ensure the correct response is sent to the pre-signed URL that comes with the event.

To make this easier, a wrapper exists to allow the creation of custom resources without having to handle that.

Sample Function

This sample will safely 'Echo' back anything given into the Echo parameter within the Custom Resource call.


import (
    "context"
    "fmt"

    "github.com/aws/aws-lambda-go/cfn"
    "github.com/aws/aws-lambda-go/lambda"
)

func echoResource(ctx context.Context, event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
    v, _ := event.ResourceProperties["Echo"].(string)

    data = map[string]interface{} {
        "Echo": v,
    }

    return
}

func main() {
	lambda.Start(cfn.LambdaWrap(echoResource))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomResourceFunction

type CustomResourceFunction func(context.Context, Event) (physicalResourceID string, data map[string]interface{}, err error)

CustomResourceFunction is a representation of the customer's Custom Resource function. LambdaWrap will take the returned values and turn them into a response to be sent to CloudFormation.

type CustomResourceLambdaFunction

type CustomResourceLambdaFunction func(context.Context, Event) (reason string, err error)

CustomResourceLambdaFunction is a standard form Lambda for a Custom Resource.

func LambdaWrap

func LambdaWrap(lambdaFunction CustomResourceFunction) (fn CustomResourceLambdaFunction)

LambdaWrap returns a CustomResourceLambdaFunction which is something lambda.Start() will understand. The purpose of doing this is so that Response Handling boiler plate is taken away from the customer and it makes writing a Custom Resource simpler.

func myLambda(ctx context.Context, event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
	physicalResourceID = "arn:...."
	return
}

func main() {
	lambda.Start(cfn.LambdaWrap(myLambda))
}

type Event

type Event struct {
	RequestType           RequestType            `json:"RequestType"`
	RequestID             string                 `json:"RequestId"`
	ResponseURL           string                 `json:"ResponseURL"`
	ResourceType          string                 `json:"ResourceType"`
	PhysicalResourceID    string                 `json:"PhysicalResourceId,omitempty"`
	LogicalResourceID     string                 `json:"LogicalResourceId"`
	StackID               string                 `json:"StackId"`
	ResourceProperties    map[string]interface{} `json:"ResourceProperties"`
	OldResourceProperties map[string]interface{} `json:"OldResourceProperties,omitempty"`
}

Event is a representation of a Custom Resource request

type RequestType

type RequestType string

RequestType represents the types of requests that come from a CloudFormation stack being run

const (
	RequestCreate RequestType = "Create"
	RequestUpdate RequestType = "Update"
	RequestDelete RequestType = "Delete"
)

type Response

type Response struct {
	Status             StatusType             `json:"Status"`
	RequestID          string                 `json:"RequestId"`
	LogicalResourceID  string                 `json:"LogicalResourceId"`
	StackID            string                 `json:"StackId"`
	PhysicalResourceID string                 `json:"PhysicalResourceId"`
	Reason             string                 `json:"Reason,omitempty"`
	NoEcho             bool                   `json:"NoEcho,omitempty"`
	Data               map[string]interface{} `json:"Data,omitempty"`
	// contains filtered or unexported fields
}

Response is a representation of a Custom Resource response expected by CloudFormation.

func NewResponse

func NewResponse(r *Event) *Response

NewResponse creates a Response with the relevant verbatim copied data from a Event

func (*Response) Send

func (r *Response) Send() error

Send will send the Response to the given URL using the default HTTP client

type StatusType

type StatusType string

StatusType represents a CloudFormation response status

const (
	StatusSuccess StatusType = "SUCCESS"
	StatusFailed  StatusType = "FAILED"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL