项目作者: kylelaker

项目描述 :
Fn::Join: [' ', ['Make', 'CloudFormation', 'strings', 'goodly!']]
高级语言: Python
项目地址: git://github.com/kylelaker/cfn-joiner-parser.git
创建时间: 2020-02-07T00:44:56Z
项目社区:https://github.com/kylelaker/cfn-joiner-parser

开源协议:MIT License

下载


CloudFormation Joiner/Parser

Are you reading old CloudFormation docs and blog posts from before
Fn::Sub
existed? Do you have a coworker who just really loves to keep using
Fn::Join
and writes it like it’s their first language? The syntax is awful to read and write, whether
in YAML or JSON. Luckily, it’s pretty easy to automate creating.

joiner.py

Pass joiner.py a file (or just send the data over stdin) that contains your string, and joiner
will join it with ''. Quickly generate those long !Join calls for a convenient conversation.
For readability and ease of commenting, joiner.py only support printing in YAML. Also, for
consistency, you may only split on ''.

  1. $ echo "Wow! Your CloudFormation is really good" | joiner.py
  2. Fn::Join:
  3. - ''
  4. - - W
  5. - o
  6. - w
  7. - '!'
  8. - ' '
  9. - Y
  10. - o
  11. - u
  12. - r
  13. - ' '
  14. - C
  15. - l
  16. - o
  17. - u
  18. - d
  19. - F
  20. - o
  21. - r
  22. - m
  23. - a
  24. - t
  25. - i
  26. - o
  27. - n
  28. - ' '
  29. - i
  30. - s
  31. - ' '
  32. - r
  33. - e
  34. - a
  35. - l
  36. - l
  37. - y
  38. - ' '
  39. - g
  40. - o
  41. - o
  42. - d
  43. - '
  44. '

parser.py

Pass parser.py a file (or again, just send the data over stdin) with your long Fn::Join call
and parser.py will turn it into a beautiful string that you can actually communicate to a human
being. No CloudFormation function except Fn::Join is support. Only the Fn::Join call is
supported.

  1. $ cat << EOF | ./parser.py
  2. Fn::Join:
  3. - ''
  4. - - W
  5. - o
  6. - w
  7. - '!'
  8. - ' '
  9. - Y
  10. - o
  11. - u
  12. - r
  13. - ' '
  14. - C
  15. - l
  16. - o
  17. - u
  18. - d
  19. - F
  20. - o
  21. - r
  22. - m
  23. - a
  24. - t
  25. - i
  26. - o
  27. - n
  28. - ' '
  29. - i
  30. - s
  31. - ' '
  32. - r
  33. - e
  34. - a
  35. - l
  36. - l
  37. - y
  38. - ' '
  39. - g
  40. - o
  41. - o
  42. - d
  43. - '
  44. '
  45. EOF
  46. Wow! Your CloudFormation is really good

FAQs

Couldn’t you have just used a single file and made one script with a flag to toggle the direction?

I guess I didn’t consider that while lost admiring the beauty of CloudFormation.

Wasn’t this waste of time?

Yes.

Did you really need to share this with the world?

No.

How can I use this to replace cat(1)?

Put these scripts somewhere that they’ll be on your path. Then put the following function at the
end of your shell’s rc file.

  1. cat() {
  2. /bin/cat "$@" | joiner.py | parser.py
  3. }

License

This work is licensed under the MIT license, that way you’re free to incorporate it into whatever
work you’d like.