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

Cannot pass Dynamic path to a nested application using !Sub or !Ref intrinsic functions #3144

Closed
jay-patel-simformsolutions opened this issue May 3, 2023 · 6 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@jay-patel-simformsolutions
Copy link

jay-patel-simformsolutions commented May 3, 2023

parent-application.yaml

ChildApplication:
    Type: AWS::Serverless::Application
    Properties:
      Location: resources/child1-application.yaml
      Parameters:
        Env: !Ref Env

And consider we have child1-application.yaml and child2-application.yaml in the resource directory so a static location path resource/child1-application.yaml works fine but !Sub resource/${Env}-applicaion.yaml does not work where Env is a command-line argument that is passed child1. It gives an error that the applicationId is missing, but the same error does not occur when I use static resources/child1-application.yaml

@jay-patel-simformsolutions jay-patel-simformsolutions added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label May 3, 2023
@awood45
Copy link
Member

awood45 commented May 3, 2023

I don't quite follow some of the explanation - can you perhaps give me a minimal set of reproducing steps for this?

@awood45 awood45 added the blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. label May 3, 2023
@jay-patel-simformsolutions
Copy link
Author

jay-patel-simformsolutions commented May 4, 2023

Thanks for responding @awood45
Sure, Basically I want to create 2 stacks 1 is parent stack and the other one is child stack, I want the child stack to be dynamic. To be very specific the child stack contains database. Now I want that for each env a database is created with a different specification, for eg. the prd, stg, uat must have a aurora-postgresql instance and the dev, test, playground and other short living environments should have simple RDS with postgresql instance to reduce the cost.

Code level example:
Our folder tree is something like this:
parent-stack.yaml
resources/
- some-nested-stack.yaml
- some-nested-stack2.yaml
- prd-database.yaml
- stg-database.yaml
- dev-database.yaml

parent-stack.yaml

Resources
.
.
.
    DatabaseStack:
        Type: AWS::Serverless::Application
        Properties:
            Location: resources/prd-database.yaml
            Parameters:
                Env: !Ref Env

So the above code example works perfectly fine because it is a static path in the template.yaml file itself. But what I am trying to achieve is I take a command line argument and make the Location Property for DatabaseStack dynamic. For e.g.
parent-stack.yaml

Parameter:
    Env:
         Type: String
         Description: Specifies the Environment that we want to deploy
Resources:
.
.
.
    DatabaseStack:
        Type: AWS::Serverless::Application
        Properties:
            Location: !Sub resources/${Env}-database.yaml
            Parameters:
                   Env: !Ref Env

This gives me an error that the ApplicationId is required, Where as a static path was working correctly

I hope this gives more clarity

@awood45
Copy link
Member

awood45 commented May 5, 2023

This seems to be a case where the language extensions capability should help - can you try it? Described here: #2533

@awood45
Copy link
Member

awood45 commented May 8, 2023

I think one challenge with this though is that you're using a !Sub property where everything appears to be local - is it safe to say your local file structure handles all of this?

If you were referring to uploaded SAR applications this would make more sense, but this isn't really what !Sub is meant to be used for if not - you're mixing things that resolve at deployment time with things that resolve at build time.

What I'd recommend instead is different templates for each environment, or having your embedded application accept a parameter and do the appropriate configuration.

Let me know if that helps - otherwise I can add this as a feature request discussion.

@awood45
Copy link
Member

awood45 commented May 8, 2023

In fact, this seems to cover the same ground as aws/aws-sam-cli#4767

@awood45
Copy link
Member

awood45 commented May 8, 2023

I'm going to close this and recommend adding a plus-one to the linked issue if you want to use this pattern. The failure is before we get to any SAM Transform steps, so you'd be making a feature request for SAM CLI to process some intrinsic functions directly. If you're actually using deployed SAR applications in some way and see this issue, feel free to reopen.

@awood45 awood45 closed this as completed May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

2 participants