aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Panic: Interface conversion error for BatchSize in Dynamodb Stream Event

Open thijs-jung-trv opened this issue 9 years ago • 4 comments

Issue

When validating a template that contains a Dynamodb Stream Event with a BatchSize I get the following error: panic: interface conversion: interface {} is int, not string. The complete stack trace is added below.

Reproduce

The following example yaml file (from AWS examples under Events) gives me the same error:

# template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  FunctionName:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      Events:
        Stream:
          Type: DynamoDB
          Properties:
            Stream: !GetAtt DynamoDBTable.StreamArn
            BatchSize: 100
            StartingPosition: TRIM_HORIZON 

Run:

$ sam validate

Output:

$ sam validate
2017/08/14 10:37:51 0.1.0
panic: interface conversion: interface {} is int, not string

goroutine 1 [running]:
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.scaffoldEventSourceMap(0x196b820, 0xc4204eb950, 0x1675e2d)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function-event-source.go:102 +0x6c6
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*functionTemplate).Scaffold(0xc420116000, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0xe, 0x168b7c4, 0x26, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:160 +0x583
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).Scaffold(0x19bcdc0, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0x26, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:80 +0x6a
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources.(*awsServerlessFunction).ClassConstructor(0x19bcdc0, 0x196b860, 0xc42029f7e0, 0x0, 0x0, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/resources/aws-serverless-function.go:61 +0x55
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.postProcess(0x196e4e0, 0xc42028a320, 0x196e4e0, 0xc42028a320, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/post-process.go:46 +0x533
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Parse(0xc42039d200, 0x19a, 0x600, 0x19a, 0x600, 0x0, 0x0, 0xc42000c050, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:72 +0x407
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.read(0x1966360, 0xc42000c050, 0xc42000c050, 0x0, 0x0, 0x0, 0x1, 0x1)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:40 +0x105
github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation.Open(0xc4201b3119, 0xd, 0xc4201b3119, 0xd, 0x13, 0x0, 0x0, 0xc420310f90)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/awslabs/goformation/goformation.go:29 +0x27e
main.validate(0xc420172640)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/validate.go:13 +0x7a
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.HandleAction(0x1587e60, 0x169a720, 0xc420172640, 0xc42043c900, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:487 +0x7c
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.Command.Run(0x1677894, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x16971ee, 0xa7, 0x0, ...)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/command.go:207 +0xb72
github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli.(*App).Run(0xc42046d040, 0xc42000a280, 0x2, 0x2, 0x0, 0x0)
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/vendor/github.com/codegangsta/cli/app.go:250 +0x7d0
main.main()
	/home/ubuntu/repo/src/github.com/awslabs/aws-sam-local/main.go:302 +0x1be1

Fix

When I change BatchSize: 100 to BatchSize: '100' the template is found valid.

$ sam validate
2017/08/14 10:38:01 0.1.0
Valid!

Further digging

$ aws cloudformation validate-template doesn't care about whether BatchSize is a string or an integer. I hope this is enough information, let me know I can supply you with anything else!

thijs-jung-trv avatar Aug 14 '17 08:08 thijs-jung-trv

Hi Thijs,

Thanks for the detailed report! There's a bug in goformation, that treats event properties always as strings. I'll submit a PR soon.

Thanks!

pesama avatar Aug 14 '17 10:08 pesama

Hey Pelayo,

Thanks for the quick reply. Good luck with the fix and keep up the good work!

Cheers!

thijs-jung-trv avatar Aug 15 '17 08:08 thijs-jung-trv

We're rewriting some of the library we use for CloudFormation/SAM parsing (github.com/awslabs/goformation) to make it more resilient against issues like this.

I can confirm this bug is fixed in the 0.1.0 branch of goformation, however we've got a bit more work to do before we can start using it in SAM Local. Shouldn't be much longer.

PaulMaddox avatar Aug 18 '17 06:08 PaulMaddox

Fixed in v0.2.0

sanathkr avatar Aug 20 '17 06:08 sanathkr