Expansion of variables / functions in Cloud Formation YAML

huangapple go评论54阅读模式
英文:

Expansion of variables / functions in Cloud Formation YAML

问题

I'm trying to learn how to write Cloud Formation templates (in YAML) by hand. I'm finding the iteration process quite slow and, therefore, learning by 'trial and error' also slow. For example, I'm trying to figure out if this:

Fn::Join: 
    - "/"
    - - "s3:/"
      - !Ref MyBucket
      - "deviceFeed"

could be replaced with this:

!Sub "s3://${MyBucket}/deviceFeed"

Is there someway that I can quickly run my YAML through a process to expand out functions like these and see the final rendered strings, etc.? Perhaps something in the CLI or console? At the moment I'm just deploying the stacks and trawling through the errors, then guessing the mistake. My pace is glacial on a particularly cold day. I need a way to move faster. Any tips greatly appreciated.

英文:

I'm trying to learn how to write Cloud Formation templates (in YAML) by hand.

I'm finding the iteration process quite slow and, therefore, learning by 'trial and error' also slow.

For example, I'm trying to figure out if this:

Fn::Join: 
	- "/"
    - - "s3:/"
      - !Ref MyBucket
	  - "deviceFeed"

could be replaced with this:

!Sub "s3://${MyBucket}/deviceFeed" 

(I have no idea of the answer to that question btw... and the answer is not what I'm asking here).

Is there someway that I can quickly run my YAML through a process to expand out functions like these and see the final rendered strings etc? Perhaps something in the CLI or console? At the moment I'm just deploying the stacks and trawling through the errors, then guessing the mistake. My pace is glacial on a particularly cold day. I need a way to move faster.

Any tips greatly appreciated.

答案1

得分: 1

I do not have 50+ reputation points, so I'm leaving an answer. That being said...

First:

!Sub "s3://${MyBucket}/deviceFeed"

This is perfectly correct and even better than Fn::Join in plain YAML CloudFormation templates. !Ref to MyBucket would return the name of the bucket.

Reference on S3 Buckets return values

Second:

CloudFormation doesn't provide a feature like terraform's plan command. And as @jarmod said, !Ref's to resources created in the template will only return values after creation. A way to have a dry run report, is creating changesets... The changeset will show you what will change in your stack, but won't help much if there are errors in the template as it doesn't run deep lint checks on the yaml file.

Here's an article that goes deep into cloudformation changesets

英文:

I do not have 50+ reputation points, so I'm leaving an answer. That being said...

First:

!Sub "s3://${MyBucket}/deviceFeed"

This is perfectly correct and even better than Fn::Join in plain YAML CloudFormation templates. !Ref to MyBucket would return the name of the bucket.

Reference on S3 Buckets return values

Second:

CloudFormation doesn't provide a feature like terraform's plan command. And as @jarmod said, !Ref's to resources created in the template will only return values after creation. A way to have a dry run report, is creating changesets... The changeset will show you what will change in your stack, but won't help much if there are errors in the template as it doesn't run deep lint checks on the yaml file.

Here's an article that goes deep in to cloudformation changesets

huangapple
  • 本文由 发表于 2023年4月4日 07:45:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定