realestate-com-au / stackup

a simple CLI and Ruby API for AWS CloudFormation
MIT License
97 stars 34 forks source link

Unhelpful error message when parameters file contains unknown keys #43

Closed amcinnes closed 6 years ago

amcinnes commented 7 years ago

I'm getting this error:

/usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:56:in `public_send': undefined method `stack_name=' for #<Stackup::ParameterStruct:0x005620462f23a0> (NoMethodError)
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:56:in `block in initialize'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:52:in `each'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:52:in `initialize'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:19:in `new'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:19:in `block (2 levels) in hashify'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:18:in `each'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:18:in `block in hashify'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:17:in `tap'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:17:in `hashify'
    from /usr/local/bundle/gems/stackup-1.1.2/lib/stackup/parameters.rb:10:in `new'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:134:in `block in parameters_from_files'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:133:in `map'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:133:in `parameters_from_files'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:207:in `parameters'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:189:in `execute'
    from /usr/local/bundle/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:58:in `run'
    from /usr/local/bundle/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    from /usr/local/bundle/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:58:in `run'
    from /usr/local/bundle/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run'
    from /usr/local/bundle/gems/clamp-1.1.2/lib/clamp.rb:6:in `Clamp'
    from /usr/local/bundle/gems/stackup-1.1.2/bin/stackup:18:in `<top (required)>'
    from /usr/local/bundle/bin/stackup:22:in `load'
    from /usr/local/bundle/bin/stackup:22:in `<main>'

when running this command:

docker run --rm \
        -v `pwd`:/cwd \
        -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN \
        -e AWS_DEFAULT_REGION="$REGION" \
        realestate/stackup:latest "$STACK_NAME" up -t "$TEMPLATE" -p "$PARAMETERS"

I'm not sure exactly what I'm doing wrong, and the error message certainly doesn't make it obvious.

amcinnes commented 7 years ago

Oh, I know what the issue is -- I used a parameters.json file that I was previously using with some other deployment tool, and it had some "special" things in it rather than the usual ParameterKey and ParameterValue fields.

mdub commented 7 years ago

Does this still need attention, @amcinnes?

If so, can you provide a (minimal) input file that demonstrates the problem, and a suggestion about what a better error message might be?

amcinnes commented 7 years ago

Okay, here's a minimal template (template.json):

{
    "Parameters": {
        "woop": {
            "Type": "String"
        }
    },
    "Resources": {
        "Topic": {
            "Type": "AWS::SNS::Topic"
        }
    }
}

and a minimal parameters file which causes the problem (parameters.json):

[
    {
        "ParameterKey": "woop",
        "ParameterValue": "pie",
        "StackName": "spam"
    }
]

and the command to deploy it:

docker run --rm \
    -v `pwd`:/cwd \
    -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN \
    -e AWS_DEFAULT_REGION=ap-southeast-2 \
    realestate/stackup:latest angus-test-stack up -t template.json -p parameters.json

The problem is that I have this StackName key in parameters.json which shouldn't be there. Without that line, the stack deploys successfully.

With that StackName line there, I would ideally see an error message like `Invalid key "StackName" in parameters file" instead of a Ruby stacktrace.

mdub commented 7 years ago

Got it. Thanks.