Skip to content

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

@vmadura

Description

@vmadura

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: #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/cfnissue or feature request related to the cfn package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions