Skip to content

Cloudformation get an inner attribute value

0

I have something like this in a yaml file:

  SomeResource:
    Type: 'AWS::Something'
    Properties:
      Name: 'MyName'

  AnotherResource:
    Type ...
    Properties:
      Name: <How can I get SomeResource.Properties.Name's value ?>

I want to be able to reuse the attribute SomeResource.Properties.Name but I can't seem to get it using !Ref or !GetAtt.

Please advise,
Thanks

asked a year ago331 views
1 Answer
2
Accepted Answer

In CloudFormation, you can reference the properties of one resource within another, but directly referencing a property like you want (e.g., SomeResource.Properties.Name) is not straightforward because CloudFormation does not support direct references to a property value. However, you can work around this by using parameters or mappings if the value is known upfront, or by using outputs and intrinsic functions like !Ref or !Sub to achieve similar functionality.

  1. Parameters are useful for reusing values across multiple resources within the same template or across different templates.
  2. Mappings are useful when you have a set of predefined values that you need to use.
  3. Outputs and Cross-Stack References are useful for sharing values between different CloudFormation stacks.
  4. Substitution with !Sub allows you to reuse values within the same stack if they are static or generated dynamically at deployment time.
Resources:
  SomeResource:
    Type: 'AWS::Something'
    Properties:
      Name: 'MyName'

  AnotherResource:
    Type: 'AWS::AnotherThing'
    Properties:
      Name: !Sub '${SomeResourceName}'

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
  • Thank you. In your example, where does SomeResourceName defined?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.