-
Notifications
You must be signed in to change notification settings - Fork 81
Closed
Labels
Description
Example yaml:
apiGatewayServiceProxies:
- sqs:
path: /queue
method: post
queueName: !GetAtt MyQueue.QueueName
cors: true
authorizationType: 'AWS_IAM'
requestParameters:
'integration.request.querystring.MessageAttribute.1.Name': "'cognitoIdentityId'"
'integration.request.querystring.MessageAttribute.1.Value.StringValue': 'context.identity.cognitoIdentityId'
'integration.request.querystring.MessageAttribute.1.Value.DataType': "'String'"
'integration.request.querystring.MessageAttribute.2.Name': "'cognitoAuthenticationProvider'"
'integration.request.querystring.MessageAttribute.2.Value.StringValue': 'context.identity.cognitoAuthenticationProvider'
'integration.request.querystring.MessageAttribute.2.Value.DataType': "'String'"
Example client code:
import Auth from '@aws-amplify/auth';
import { AwsClient } from 'aws4fetch';
const endpoint = process.env.REACT_APP_ENDPOINT || '';
export const queue = async (url: string) => {
const credentials = await Auth.currentCredentials().then(creds =>
Auth.essentialCredentials(creds),
);
const aws = new AwsClient(credentials);
await aws.fetch(`${endpoint}/queue`, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Hello World',
}),
});
};
Example function code:
import { SQSHandler, SQSEvent } from 'aws-lambda';
export const handler: SQSHandler = async (event: SQSEvent) => {
const { Records: records } = event;
const record = records[0];
const cognitoIdentityId = record.messageAttributes['cognitoIdentityId'].stringValue || '';
const cognitoAuthenticationProvider = record.messageAttributes['cognitoAuthenticationProvider'].stringValue ||
'';
// do something with the attributes
}