Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: a new Fn::Get intrinsic function to get a value by key from (JSON) data #129

Open
mrinaudo-aws opened this issue Jun 23, 2023 · 3 comments

Comments

@mrinaudo-aws
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Tell us about your request

What do you want us to build?
An intrinsic function to retrieve a value from JSON data, given a specified key. For example, given the following example output that the AwsCommunity::Resource::Lookup resource type would return for a given resource type target of a lookup using !GetAtt ResourceLookup.ResourceProperties (content has been omitted, and formatted using a two-space, newline indentation):

{
  "VpcId": "vpc-[OMITTED]",
  "InstanceTenancy": "default",
  "CidrBlockAssociations": [
    "vpc-cidr-assoc-[OMITTED]"
  ],
  "CidrBlock": "[OMITTED]",
  "DefaultNetworkAcl": "acl-[OMITTED]",
  "EnableDnsSupport": true,
  "Ipv6CidrBlocks": [],
  "DefaultSecurityGroup": "sg-[OMITTED]",
  "EnableDnsHostnames": true,
  "Tags": [
    {
      "Key": "Name",
      "Value": "Test"
    }
  ]
}

I would like to have a new intrinsic function, e.g., Fn::Get, to consume a value given its key. The value can be a string, a boolean, a list (whereas I could plug in Fn::Select for example to get a value given its index), a map, et cetera.

Tell us about the problem you are trying to solve. What are you trying to do, and why is it hard?

I think that having a native way (as opposed to building/maintaining one) for the above use case or similar ones, is desirable.

Are you currently working around this issue?

Thinking of experimenting with a custom logic to fetch value(s) I'd need - for example, a custom resource/resource type.

What is the expected behavior with this new feature

I want to be able to reference an input block (in the example above, the resource properties), and a path to navigate the property tree. An initial, simplified example could just reference to the key name (as in the example below), or use a JMESPath expression to retrieve nested structures:

Resources:
  MySubnet:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.0.0.0/24
      AvailabilityZone: "us-east-1a"
      VpcId:
        Fn::Get:
          - !GetAtt ResourceLookup.ResourceProperties
          - VpcId

Additional context

-

Attachments

-

@josb
Copy link

josb commented Jul 10, 2023

It would be excellent if this also worked on String parameters, because it would provide for structured data as parameter values. While it would be preferable for CloudFormation to understand structured parameters natively (see e.g. #46), this would be immediately helpful to group information together in a single parameter.

@Zuhairahmed
Copy link

just FYI, this is super helpful for us at MongoDB publisher side if CFN team could adopt this GitHub issue. this would help several of our joint-customers. happy to share more details if you need! cc: @mrinaudo-aws @lantoli

@mrinaudo-aws
Copy link
Author

Not an intrinsic function, but I built this example custom resource that returns a value from JSON data and a search argument you both specify. Feel free to try it out (you can also test it locally): https://github.com/aws-cloudformation/aws-cloudformation-templates/blob/main/CloudFormation/CustomResources/getfromjson/README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants