Accessing GraphQL URL from custom nested stacks
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 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"
]
]
}
}
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.
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"
}
}
}
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.
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 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 :)
+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.
@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"
]
}
}
+1
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.