Amplify-cli: Make export name of the stack's output reachable

Created on 7 Mar 2019  路  3Comments  路  Source: aws-amplify/amplify-cli

Is your feature request related to a problem? Please describe.
Currently, there is no easy way to get an output from a stack. It is because the export name is generated using the current stack's name, and we end up with a large name that changes for each environment we have. This makes getting the output of a stack impossible.

For example:
The generated API CloudFormation template has this output defined

"Outputs": {
    "GraphQLAPIIdOutput": {
        "Description": "Your GraphQL API ID.",
        "Value": {
            "Fn::GetAtt": [
                "GraphQLAPI",
                "ApiId"
            ]
        },
        "Export": {
            "Name": {
                "Fn::Join": [
                    ":",
                    [
                        {
                            "Ref": "AWS::StackName"
                        },
                        "GraphQLApiId"
                    ]
                ]
            }
        }
    }
}

The resulting export name is something ParentStackName-ResourceName-AWSUniqueID. We can not hardcoded that name in another stack, for example, a function, because it will fails when deploying new env if the old stack is removed, or we end up pointing to a service in another stack.

Describe the solution you'd like
From the parent stack(amplify/backend/awscloudformation/nested-cloudformation-stack.yml) pass as a _parameteter_ to all the child stacks the AWS::StackName. For example:

"Parameters": {
    "ParentStackName": { "Fn::Sub": "${AWS::StackName}" }
}

And childs to childs and so on:

"Parameters": {
    "ParentStackName": { "Fn::Sub": "${ParentStackName}" }
}

In order to be able to use that value when exporting an output

"Outputs": {
    "GraphQLAPIIdOutput": {
        "Description": "Your GraphQL API ID.",
        "Value": {
            "Fn::GetAtt": [
                "GraphQLAPI",
                "ApiId"
            ]
        },
        "Export": {
            "Name": {
                "Fn::Join": [
                    ":",
                    [
                        {
                            "Fn::Sub": "${ParentStackName}"
                        },
                        "GraphQLApiId"
                    ]
                ]
            }
        }
    }
}

This will make all the exports available in any CloudFormation template in the app.

"Fn::ImportValue": {
    "Fn::Join": [
        ":",
        [
            {
                "Fn::Sub": "${ParentStackName}"
            },
            "GraphQLApiId"
        ]
    ]
}

Additional context
For this to fully works, must be a mecanism to define a DependsOn and controll the order in which stacks are created. But it can be another issue.

enhancement graphql-transformer platform

Most helpful comment

Because of this issue, attaching a custom resolver for an AWS lambda as described here (https://aws-amplify.github.io/docs/cli/graphql#add-a-custom-resolver-that-targets-an-aws-lambda-function) is effectively impossible in a multienv setting. Each env is going to have a different AppSync with a different id that is not reference-able via CloudFormation.

All 3 comments

@kstro21 Thanks for the feedbacks. We will discuss it among the team.

Because of this issue, attaching a custom resolver for an AWS lambda as described here (https://aws-amplify.github.io/docs/cli/graphql#add-a-custom-resolver-that-targets-an-aws-lambda-function) is effectively impossible in a multienv setting. Each env is going to have a different AppSync with a different id that is not reference-able via CloudFormation.

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jkeys-ecg-nmsu picture jkeys-ecg-nmsu  路  3Comments

kangks picture kangks  路  3Comments

davo301 picture davo301  路  3Comments

nicksmithr picture nicksmithr  路  3Comments

onlybakam picture onlybakam  路  3Comments