Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vmadura opened this issue Aug 19, 2018 · 2 comments
Open

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

vmadura opened this issue Aug 19, 2018 · 2 comments
Labels
type/cfn issue or feature request related to the cfn package

Comments

@vmadura
Copy link
Contributor

vmadura commented Aug 19, 2018

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

@bmoffatt
Copy link
Collaborator

reopening per #241

@bmoffatt bmoffatt reopened this Feb 12, 2020
@bmoffatt bmoffatt added the type/cfn issue or feature request related to the cfn package label Dec 20, 2022
@rix0rrr
Copy link

rix0rrr commented Mar 13, 2025

Hey there! This is still a problem for us in https://github.com/cdklabs/cdk-ecr-deployment.

Any chance on getting some traction on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/cfn issue or feature request related to the cfn package
Projects
None yet
Development

No branches or pull requests

3 participants