Accessing AppSync environmental variables in resolver

0

how to access AppSync environmental variables in resolver

Jehan
質問済み 1ヶ月前151ビュー
2回答
2

With the recent update to AWS AppSync, you can now access environment variables directly in your GraphQL resolvers and functions. You can define these environment variables in the AWS AppSync console or using infrastructure as code tools like AWS CloudFormation or the AWS Cloud Development Kit (CDK). At runtime, you can access these variables in your resolver and function code, enabling dynamic configuration of your GraphQL API without modifying the code implementation.

For more details, you can refer to the Environmental Variables.

profile picture
エキスパート
回答済み 1ヶ月前
  • Can I know how exactly I can get the account id in the resolver? (Ex to get the token I use this: #set($token = $context.request.headers.get("Authorization")) )

  • You can use the $context.identity.accountId property in your resolver mapping template. This property is available when using AWS_IAM as the authorization type. Here's an example of how to set and use it:

    #set($accountId = $context.identity.accountId)

    You can then use the $accountId variable in your resolver logic as needed.

    Important Sources

  • Thanks. But I'm using Cognito for authorization. Therefore I cannot use this method. Therefore what I'm trying to do is define account id as an environmental variable in appsync so that I can access it from the resolver so that I don't have to hard code account id into the resolver itself. Therefore I need to know how to access environmental variables in the resolver.

0
承認された回答

I can access environment variables defined in appsync as #set($accountId = $context.env.account_id)

Jehan
回答済み 1ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ