0

I'm using AWS CDK to build a cloudformation stack with HttpApi in it. HttpApi will have an integration with SQS.

I have the following snippet:

import * as ApiGW2 from "@aws-cdk/aws-apigatewayv2-alpha";

const httpApi = new ApiGW2.HttpApi(this, "http-api", {
  apiName: "dev-api"
});

const int = new ApiGW2.HttpIntegration(this, "int1", {
  httpApi,
  integrationType: ApiGW2.HttpIntegrationType.AWS_PROXY,
  integrationSubtype: ApiGW2.HttpIntegrationSubtype.SQS_SEND_MESSAGE,
  payloadFormatVersion: ApiGW2.PayloadFormatVersion.VERSION_1_0,
})

But I get an error when running this code:

UPDATE_ROLLBACK_COMPLETE: Role ARN must be specified for AWS integration configuration with Subtype: SQS-SendMessage

1 Answer 1

1

The API Gateway service needs permission to send messages to your queue. Create a role assumable by the API Gateway service. Grant the role send permissions on your queue. Pass the role to the integration in the credentials prop:

const sqsRole = new iam.Role(this, "Role", {
  assumedBy: new iam.ServicePrincipal("apigateway.amazonaws.com"),
});

myQueue.grantSendMessages(sqsRole);

const credentials = ApiGW2.IntegrationCredentials.fromRole(sqsRole);

const int = new ApiGW2.HttpIntegration(this, "int1", {
  httpApi,
  integrationType: ApiGW2.HttpIntegrationType.AWS_PROXY,
  integrationSubtype: ApiGW2.HttpIntegrationSubtype.SQS_SEND_MESSAGE,
  payloadFormatVersion: ApiGW2.PayloadFormatVersion.VERSION_1_0,
  credentials, // <-- connects the role to the integration
})
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @fedonev! It works, the integration gets created but I can't use it in addRoute of HttpApi. httpApi.addRoutes({ path: "/toSqs", integration: int }) I’ve got compile error: Type HttpIntegration is missing the following properties from type HttpRouteIntegratio
Glad to help, @AlexanderKondaurov. See the open GitHub issue apigatewayv2-integrations: Add support for SQS-SendMessage integration. The comments include a DIY implementation of a HttpRouteIntegration class for SQS-SendMessage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.