Adding custom headers
See original GitHub issueHi,
I am looking for the way to add a custom header in all the request sent to AppSync. I was able to do it with the Amplify library but since I need some the advanced functionnalities from aws-appsync-sdk, I am trying to do it with the appsync-sdk as well.
I didn’t find any documentation on this topic. Is there a way to do it?
For example, I tried to add request option when creating the AWSAppSyncClient without any success:
const appSyncClient = new AWSAppSyncClient({
url: config.amplify_config.aws_appsync_graphqlEndpoint,
request: async (operation) => {
const user = await Auth.currentUserInfo();
logger.debug("AWSAppSyncClient request:", user);
operation.setContext({
headers: {
'amt-custom-username': user.username
}
});
},
region: config.amplify_config.aws_appsync_region,
auth: {
type: AUTH_TYPE.AWS_IAM,
credentials: () => Auth.currentCredentials(),
},
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @OlivierPT
Try this sample code here
In order to read the custom header on your request mapping template use this $context.request.headers.your_header_name
I used this on the previous sample
Let me know how it goes
@elorzafe you are an absolute legend. Copied your sample into my project and used
$context.request.headers.your_header_name
in my request mapping to get my custom header. Worked first time!In my case I am accessing a graphql api through a lambda and using IAM credentials. Here is my code to setup the AWSAppSyncClient if anyone is interested.