Kotaimen / awscfncli

Friendly AWS CloudFormation CLI
MIT License
59 stars 12 forks source link

Some strings with leading 0s are converted from string to numbers #96

Open alytle opened 4 years ago

alytle commented 4 years ago

I ran into an interesting issue today. I have a SNS Subscription with a filter policy which uses a list of strings of numerical values to create filters. It looks something like this:

      FilterPolicy:
        FILTER_CODE:
          - "1234"
          - "0900"
          - "0500"

When the template is deployed, I end up with a template which looks like:

      FilterPolicy:
        FILTER_CODE:
          - "1234"
          - 900        <--- converted to an integer
          - "0500"     

I traced it to the cfn package command by adding a --verbose:

Syncing stack ...
StackName: ...
...
--- start of TemplateBody ---
AWSTemplateFormatVersion: '2010-09-09'
...
        FILTER_CODE:
        - '1234'
        - 0900
        - '0500'

So the number with a leading 0 was converted to a number, but not one which had a 0 followed by a 5. I traced the issue to a bug in the AWS CLI: https://github.com/aws/aws-cli/issues/2934 - it was fixed apparently in AWS CLI v2 because they dropped pyyaml for ruamel according to https://github.com/aws/aws-cli/issues/2934#issuecomment-610558589

Since we are consuming awscli==1.18.97 we are still experiencing this.

Apparently the workaround is to use a trivial !Join [ "", "0900" ] which will prevent the incorrect parsing.

What would it take to move our code to awscli 2?

Kotaimen commented 4 years ago

Hi @alytle,

Sure, we'll take a look.

@GlieseRay please check whether our hack is broken by awscli2? I believe it makes sense to call awscli directly instead of hacking into their code.

GlieseRay commented 4 years ago

@Kotaimen @alytle Will take a look. we will definitely move to awscli2...

Kotaimen commented 4 years ago

Hi @GlieseRay:

I did some very quick check, turns out awscli2 is not on pypi, the latest version is 1.18.121, seems AWS is pushing for a binary distribution for awscli v2... any thoughts...?

GlieseRay commented 4 years ago

Yes, and looks like they are not going to put it on pypi because of various reasons....