aws / aws-lambda-go

Libraries, samples and tools to help Go developers develop AWS Lambda functions.
Apache License 2.0
3.65k stars 555 forks source link

cfn wrapper for Cloudformation does not report correct error to aws #107

Open vmadura opened 6 years ago

vmadura commented 6 years ago

When an error is returned by the lambda wrapped by aws cfn wrapper; the PhysicalResourceID is not included. It was modified recently to include all request types: https://github.com/aws/aws-lambda-go/pull/76

However, AWS Docs mention PhysicalResourceID is always required. Therefore Cloudformation incorrectly reports the error "Invalid Physical Resource ID" instead of the actual error during resource creation.

Steps to replicate: Modified the Simple Test Lambda to include an error condition:

package main

import (
  "context"
  "fmt"
  "errors"
  "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)
    if event.RequestType == "Create" {
      if v == "ERROR" {
    err = errors.New("My Custom Resource Creation Failed")
    fmt.Errorf("Error occurred")
    return 
      } 
    }
    data = map[string]interface{} {
        "Echo": v,
    }

    return
}

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

Created simple Cloudformation template to create custom resource:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Test

Resources:
  TestResource:
    Type: "Custom::TestResource"
    Properties:
      Echo: ERROR
      ServiceToken: arn:aws:lambda:us-west-1:xxxxx:function:cfn-test

Observed that the error reported during Stack Creation is incorrect: image

The error message reported must be : My Custom Resource Creation Failed

bmoffatt commented 4 years ago

reopening per #241