Amplify-cli: expose amplify-meta.json to backend functions & apis

Created on 10 Jan 2019  路  10Comments  路  Source: aws-amplify/amplify-cli

Is your feature request related to a problem? Please describe.
Multienv support generates new resource identifiers for resources like Cognito User Pools, DynamoDB table names, and ElasticSearch endpoints. This makes referencing those resources from backend functions (added via amplify add function or amplify add api) challenging (and in some cases impossible) with hardcoding per-environment configuration outside the context of Amplify.

Describe the solution you'd like

  • As part of the build process for Lambda functions, expose a copy of amplify-meta.json that the Lambda function can use to lookup desired resource identifiers.
  • DynamoDB table names created by the GraphQL transformer are not currently exposed in amplify-meta.json; add those, please.
  • No information about the ElasticSearch service provisioned by @searchable is currently included in amplify-meta.json; add that too, please.

Describe alternatives you've considered
Alternatively consider offering full support for the front-end functions included in the aws-amplify library, such as querying of GraphQL APIs, from back-end functions. FYI it currently "just works" if you include a fetch polyfill (e.g. cross-fetch/polyfill), but the authentication process is obviously geared toward use cases with a static user (as it stores a lot of data in global state).

Additional context
Ref: #621

feature-request

Most helpful comment

how does one access environmental variables outside of those generated by amplify such as for third party services such that can be stored in the SSM parameter store? https://serverless.com/framework/docs/providers/aws/guide/variables/ is a good execution of what I hope is exposed by Amplify.

All 10 comments

Thanks for the feedbacks @troygoode

Looking forward to this feature. For now we are creating a map per env with the dynamically generated api id.

This gonna be very helpful

Today we released an updated flow as a part of the functions category to pass resource identifiers like the cognito userpool ID or graphql ID or any other resource - managed and generated by the Amplify CLI to a lambda function as environment variables and also populate the corresponding lambda execution role to access these resources. You can install the latest version of the CLI and go through the amplify update function flow to update your existing functions to access your Amplify generated resources in the project.

@kaustavghosh06 do you happen to have a sample for access the API from a lambda using something like graphqlOperation and API from 'aws-amplify' ? I'm assuming the user has to be an IAM role here, which is handled when updating the function.

@kaustavghosh06 Is there any documentation on how to use e.g. the AppSync API from your Lambda function?

how does one access environmental variables outside of those generated by amplify such as for third party services such that can be stored in the SSM parameter store? https://serverless.com/framework/docs/providers/aws/guide/variables/ is a good execution of what I hope is exposed by Amplify.

Is your feature request related to a problem? Please describe.
Multienv support generates new resource identifiers for resources like Cognito User Pools, DynamoDB table names, and ElasticSearch endpoints. This makes referencing those resources from backend functions (added via amplify add function or amplify add api) challenging (and in some cases impossible) with hardcoding per-environment configuration outside the context of Amplify.

Describe the solution you'd like

  • As part of the build process for Lambda functions, expose a copy of amplify-meta.json that the Lambda function can use to lookup desired resource identifiers.
  • DynamoDB table names created by the GraphQL transformer are not currently exposed in amplify-meta.json; add those, please.
  • No information about the ElasticSearch service provisioned by @searchable is currently included in amplify-meta.json; add that too, please.

Describe alternatives you've considered
Alternatively consider offering full support for the front-end functions included in the aws-amplify library, such as querying of GraphQL APIs, from back-end functions. FYI it currently "just works" if you include a fetch polyfill (e.g. cross-fetch/polyfill), but the authentication process is obviously geared toward use cases with a static user (as it stores a lot of data in global state).

Additional context
Ref: #621

@troygoode, could you give me some pointers on how to use cross-fetch library to archive this?

Thanks!

@kaustavghosh06

DynamoDB table names created by the GraphQL transformer are not currently exposed in amplify-meta.json; add those, please.

I this request also in the release? I don't see the dynamodb created for Appsync in the amplify-meta.json

I ran into a problem with my function going directly to DDB. I started using @key with composite sort keys and needed to go back to the function to duplicate what is being done in the mutation resolvers to construct the field.

If you're working on an app with a quickly changing schema it's going to be a headache to maintain.

Was this page helpful?
0 / 5 - 0 ratings