question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Inject the GraphQL API Id Output to all the Lambdas

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
zjullioncommented, May 24, 2019

how is this functionality hidden and undocumented?.

I’m not sure why the amplify-cli team has not documented it. I’m just a contributor here (like you!)

Is it gonna be removed? Editing backend-config.json is safe?

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 see dependsOn is used between auth and api resources.

I mean, changes won’t get lost by running amplify push/publish or others commands?

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

1reaction
zjullioncommented, May 24, 2019

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling GraphQL API from a Lambda function - Amplify Docs
First, create a Lambda function with amplify add function and choose the AppSync - GraphQL API request (with IAM) to get started. Be...
Read more >
Tutorial: Lambda resolvers - AWS AppSync
In this section, we'll show you how to write a Lambda function that performs business logic based on the invocation of a GraphQL...
Read more >
Build & Deploy AWS Lambda GraphQL APIs: 2 Easy Steps
AWS Lambda GraphQL allows you to request only the data that is needed and a runtime for fulfilling those queries with your existing...
Read more >
Use lambda resolvers in your GraphQL API with AWS Amplify
The @function directive which create a pipeline resolver to resolve our custom mutation. If you want to follow along, run amplify add api...
Read more >
How to write GraphQL Apps using AWS Lambda
As a result, all major cloud providers have some sort of serverless functionality, such as Cloud Functions by Google and Azure Functions by ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found