serverless-apigateway-service-proxy icon indicating copy to clipboard operation
serverless-apigateway-service-proxy copied to clipboard

Feature Request: Allow cross regional configuration for SNS

Open mtimbs opened this issue 4 years ago • 3 comments

When configuring apiGatewayServiceProxies in serverless.yml it would be good to be able to define either an ARN instead of a topicName OR to be able to include a region overwrite.

example

custom:
  apiGatewayServiceProxies:
    - sns:
        path: /sns
        method: post
        topicName: my-topic-name-here
        region: us-east-2
        cors: true

The reason is I use this plugin heavily with serverless-artillery to e2e and load test services. For services that only have an SNS entry point we can configure an API Gateway Service Proxy to direct the load simulation. However I run these load tests in a seperate region from my services to avoid regional scaling limits.

Apologies if this is possible but I did have a look at the library code and couldn't find any valid parameters for SNS to use an SNS or region variable

mtimbs avatar Feb 28 '20 03:02 mtimbs

Apologies, I can now see I can accomplish this with default request mapping templates.

If you don't mind can we leave this open and I will submit a PR to add this to the documentation

mtimbs avatar Feb 28 '20 03:02 mtimbs

Glad to hear that your problem has been resolved 👍

If you don't mind can we leave this open and I will submit a PR to add this to the documentation

Yes, please! Good idea.

horike37 avatar Mar 03 '20 13:03 horike37

It turns out that while a request mapping template sorted out the issue of specifying the topic to publish too, the API Gateway Integration Request Region still defaults to the region of the API itself which for reasons I don't fully understand means I get a 4xx on the request.

It is possible to have an API deployed in us-east-1 region but have the Integration request region set as us-east-2 and I believe this is configurable via the SDK.

I understand that in most cases it doesn't make sense to proxy from a gateway in one region to a service in another, but it would still be nice to have a configuration option.

For example I deploy this proxy in us-east-1 and want to integrate with an SNS topic in us-east-2 it currently won't work, I have to manually configure it in the console.

provider:
  name: aws
  runtime: nodejs10.x
  region: us-east-1

.....

custom:
  apiGatewayServiceProxies:
    - sns:
        path: /sns
        method: post
        topicName: <topic-name>
        cors: true
        request:
          template:
            application/json: "Action=Publish&Message=$util.urlEncode($input.body)&TopicArn=$util.urlEncode('arn:aws:sns:us-east-2:<account>:<topic>')"

I might look at the code a bit more and see if I can find a solution that would allow the integration region to be configurable, otherwise I'll stop trying to be clever and just proxy within the same region 🙃

mtimbs avatar Mar 03 '20 21:03 mtimbs