[Feature] Inject the GraphQL API Id Output to all the Lambdas
See original GitHub issueIs your feature request related to a problem? Please describe.
The GraphQL API Id is used to generate the DynamoDB table’s name, is also used to generate the export name of some outputs of other stacks, for example, the StreamArn
of a table. I’ve seen a few comments asking how to get the API Id from a Lambda like this one https://github.com/aws-amplify/amplify-cli/issues/1002#issuecomment-474714854
Additionally, the export name of the GraphQL API Id Output is so random that it can not be referenced easily, see this comments https://github.com/aws-amplify/amplify-cli/issues/1002#issuecomment-471125831 https://github.com/aws-amplify/amplify-cli/issues/1002#issuecomment-472120075
Describe the solution you’d like
The generated template in amplify\backend\awscloudformation\nested-cloudformation-stack.yml
should pass the GraphQL API Id Output to all the Lambdas as a parameter. Let’s call the API myamplifytest
, then, the resource identifier will be like apimyamplifytest
, so, we can get the GraphQL API Id Output and pass as a parameter
"functionmyfunction": {
"Type": "AWS::CloudFormation::Stack",
"DependsOn": ["apimyamplifytest"],
"Properties": {
"TemplateURL": "https://s3.amazonaws.com/myproject-20190306200305-deployment/amplify-cfn-templates/function/functionmyfunction-cloudformation-template.json",
"Parameters": {
"env": "dev",
"GraphQLAPIId": {
"Fn::GetAtt": ["apimyamplifytest", "Outputs.GraphQLAPIIdOutput"]
}
}
}
},
Note that all the Lambdas then will need a DependsOn
the resource that outputs the GraphQL API Id.
Additional context
This will make it easy for people writing custom logic in the Lambdas and trying to get either the GraphQL API Id, a table name, StreamArn
or any other output generated using the GraphQL API Id. Implementing this can be a way of dealing with aws-amplify/amplify-category-api#440
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:20 (13 by maintainers)
I’m not sure why the amplify-cli team has not documented it. I’m just a contributor here (like you!)
I can’t say for certain, but I think it’s fairly safe. When you add / remove resources via
amplify cli
, this is the file that gets edited. As well, you’ll seedependsOn
is used between auth and api resources.For certain, the changes won’t get lost.
Just remember to always do an 'amplify env checkout <env>` after editing the file.
As well, this file can be used to add 100% custom resources to amplify: https://github.com/aws-amplify/amplify-cli/issues/80#issuecomment-492428916
@kstro21, you can provide the GraphQLApiIdOutput to the lambdas, just follow something similar to what I mention here: https://github.com/aws-amplify/amplify-cli/issues/1481#issuecomment-493603180