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: !StringJson function #473

Open
zaro0508 opened this issue Mar 15, 2023 · 2 comments
Open

Feature request: !StringJson function #473

zaro0508 opened this issue Mar 15, 2023 · 2 comments

Comments

@zaro0508
Copy link
Contributor

zaro0508 commented Mar 15, 2023

Subject

I would like a function that's the opposite of !JsonString to support my use cases. The general use case is to convert a string to a json object then pass it to a cloudformation or TemplatingContext parameter.

Use cases

These use cases are derived from the Templating context example in the docs:

Read ports in from a file, convert the string to a json list object and then pass it to the ports parameter:

SecurityGroupExample:
  Type: update-stacks
  Template: ./security-group.njk
  StackName: SecurityGroupExample
  Parameter:
    ports: !StringJson 
      - !Readfile "ports.json"

Get data from a REST API endpoint, convert the string to a json dictionary object and then pass it to the hounds TemplatingContext parameter:

DogsExample:
  Type: update-stacks
  Template: ./dogs.njk
  StackName: DogsExample
  TemplatingContext:
    hounds: !StringJson 
      - !Cmd "wget -qO-  https://dog.ceo/api/breed/hound/list"
@OlafConijn
Copy link
Member

have you tried:

SecurityGroupExample:
  Type: update-stacks
  Template: ./security-group.njk
  StackName: SecurityGroupExample
  Parameter:
    ports: !Include "ports.json"

I dont think this will help with the !Cmd "wget -qO- https://dog.ceo/api/breed/hound/list" though....

@zaro0508
Copy link
Contributor Author

I have not tried !Include in that context @OlafConijn. I will investigate that.

I dont think this will help with the !Cmd "wget -qO- https://dog.ceo/api/breed/hound/list" though....

If !Cmd doesn't work then how about a new org-formation !Request function would basically do a "curl -X GET https://dog.ceo/api/breed/hound/list"? This is how it would work..

Get data from a REST API endpoint, convert the string to a json dictionary object and then pass it to the hounds TemplatingContext parameter:

DogsExample:
  Type: update-stacks
  Template: ./dogs.njk
  StackName: DogsExample
  TemplatingContext:
    hounds: !StringJson 
      - !Request "https://dog.ceo/api/breed/hound/list"

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

2 participants