amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Accessing GraphQL URL from custom nested stacks

Open eelzinaty opened this issue 7 years ago • 10 comments

Note: If your feature-request is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

eelzinaty avatar Jun 09 '19 10:06 eelzinaty

@eelzinaty could you provide more details about the use case? Do you want to access the generated? GraphQL transformer exports the GraphQL API endpoint under and can be imported using the following in your nested stack

{
  "Fn::ImportValue": {
    "Fn::Join": [
      ":",
      [
        {
          "Ref": "AWS::StackName"
        },
        "GraphQLApiEndpoint"
      ]
    ]
  }
}

yuth avatar Jun 10 '19 20:06 yuth

That would work if I'm initializing the parameter in other stacks like function's stack. But if I want to access this within GraphQL custom stack it will not work, as the parameter is not exported yet.

eelzinaty avatar Jun 11 '19 07:06 eelzinaty

In nested stack, you can access to the GraphQL API endpoint by using a parameter. The transformer automatically passes the needed parameter to the child stack. Add the following to your custom stacks parameter section

{
  "Parameters": {
    "GraphQLAPIEndpointOutput": {
      "Type": "String",
      "Description": "The GraphQL API Endpoint ",
      "Default": "undefined"
    }
  }
}

yuth avatar Jun 11 '19 17:06 yuth

I tried that but it did not work, the value is undefined. I might not explain my case in a good way.

I want to add a custom stack under my GraphQL API inside stacks folder. And from this new stack, I want to access the GraphQL Endpoint. The problem when I try to access the exported value the stack failed because the value is not exported yet. I'm using amplify version 1.7.0.

Thanks for your help.

eelzinaty avatar Jun 12 '19 11:06 eelzinaty

I think this parameter is not generated by the transformer. I check the code in this file and for custom stacks, it only processes AppSyncApiId.

I'm not sure if I should make a fork and change the code then make a PR or I should wait for this change.

eelzinaty avatar Jun 12 '19 12:06 eelzinaty

@eelzinaty This is not supported yet but the file you pointed to is the exact place to make it happen. AppSync GraphQLApi resources allow you to use Fn::GetAtt with the value GraphQLURL to get the url (see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html). We can add this to the backlog but would also be happy to review a PR :)

mikeparisstuff avatar Jun 13 '19 17:06 mikeparisstuff

+1 Having the same issue - I want to create a custom stack to export resources managed by Amplify (Cognito User Pool ID, AppSync ID) and I can't get the AppSync ID in my custom stack.

Ideally this parameters.json should work but it doesn't:

{
    "authcognitoa7d29d9dUserPoolId": {
        "Fn::GetAtt": [
            "authcognitoa7d29d9d",
            "Outputs.UserPoolId"
        ]
    },
    "apiawsserverlessairlineGraphQLAPIIdOutput": {
        "Fn::GetAtt": [
            "awsserverlessairline",
            "Outputs.GraphQLAPIIdOutput"
        ]
    }
}

awsserverlessairline is the resource name within amplify status output. It works for auth but not for api category.

Suggestion: Similarly to how Amplify auto-injects env parameter, it could also inject resources managed by Amplify, where we could control from a custom template parameters section what we want.

heitorlessa avatar Nov 22 '19 18:11 heitorlessa

@eelzinaty Just got it working - Issue is with amplify status command that truncates the resource name to fit the table.

You can find all Exports including correct resource names within the file: amplify/backend/awscloudformation/nested-cloudformation-stack.yml

Here's the final parameters.json that receives Cognito User Pool ID, AppSync API ID and AppSync GraphQL URL:

{
    "authcognitoa7d29d9dUserPoolId": {
        "Fn::GetAtt": [
            "authcognitoa7d29d9d",
            "Outputs.UserPoolId"
        ]
    },
    "apiawsserverlessairlineGraphQLAPIIdOutput": {
        "Fn::GetAtt": [
            "apiawsserverlessairline",
            "Outputs.GraphQLAPIIdOutput"
        ]
    },
    "apiawsserverlessairlineGraphQLAPIEndpointOutput": {
        "Fn::GetAtt": [
            "apiawsserverlessairline",
            "Outputs.GraphQLAPIEndpointOutput"
        ]
    }
}

heitorlessa avatar Nov 22 '19 19:11 heitorlessa

+1

dtelaroli avatar Jan 13 '20 19:01 dtelaroli

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 05:05 github-actions[bot]