Skip to content

add ability to pass in additional request parameters for sqs #15

@erezrokah

Description

@erezrokah

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions