Skip to content

How to switch my REST API from edge-optimized to regional and attach it to lambda as trigger?

0

Hello,

I've used serverless.yml to deploy lambda functions

...
functions:
    rest:
        handler: rest_handler.handler
        timeout: 120
        events:
            - http:
                  method: ANY
                  path: "/{proxy+}"
                  timeoutInMillis: 120000
                  cors: true
...

But it seems that the extended timeout only works for REGIONAL and not edge-optimized.

I tried switching by cloning the gateway, deploying it to a stage and attaching it as a trigger but the resource_path is always set incorrectly and I can't make the request calls.

2 Answers
1
Accepted Answer

To switch your REST API from edge-optimized to regional and attach it to Lambda as a trigger, you'll need to follow these steps:

  1. Update your API Gateway configuration: Use the AWS CLI or AWS Management Console to change the endpoint type of your API from edge-optimized to regional. With the AWS CLI, you can use the following command:

    aws apigateway update-rest-api \
        --rest-api-id your-api-id \
        --patch-operations op=replace,path=/endpointConfiguration/types/EDGE,value=REGIONAL
    

    Replace 'your-api-id' with your actual API ID.

  2. Redeploy your API: After changing the endpoint type, you need to redeploy your API to apply the changes.

  3. Update your serverless.yml: Modify your serverless.yml file to specify the regional endpoint type. Add the following configuration under the 'provider' section:

    provider:
      apiGateway:
        endpointType: REGIONAL
  4. Redeploy your serverless application: Run the serverless deploy command to apply the changes and redeploy your application.

  5. Update Lambda trigger: If you've manually set up the Lambda trigger, you may need to update it to point to the new regional endpoint. However, if you're using the Serverless Framework as shown in your configuration, it should handle this automatically.

  6. Test your API: After redeployment, test your API to ensure it's working correctly with the new regional endpoint and that the extended timeout is now applied.

Regarding the resource path issue you mentioned, ensure that your serverless.yml configuration for the http event is correct. The "{proxy+}" path should allow for catch-all routing. If you're still experiencing issues, double-check your Lambda function code to ensure it's correctly handling the incoming requests and paths.

Remember that changing the endpoint type may affect your API's behavior and performance, especially if you have geographically distributed users. Consider your use case carefully when deciding between edge-optimized and regional endpoints.
Sources
Change a public or private API endpoint type in API Gateway - Amazon API Gateway
Amazon API Gateway - Serverless Applications Lens

answered a year ago

AWS
EXPERT

reviewed a year ago

0

Hi,

To switch your REST API from edge-optimized to regional and attach it to Lambda, here's how to modify your serverless.yml:

# serverless.yml
service: your-service

provider:
  name: aws
  runtime: python3.9  # or your runtime
  region: us-east-1   # your region

functions:
  rest:
    handler: rest_handler.handler
    timeout: 120
    events:
      - http:
          method: ANY
          path: /{proxy+}
          timeoutInMillis: 120000
          cors: true
          endpointType: REGIONAL  # Add this line

custom:
  apiGateway:
    apiType: REGIONAL    # Add this section
    description: 'Regional API Gateway'

Key points:

  • Set endpointType to REGIONAL
  • Redeploy your service
  • Update DNS/CloudFront if needed
  • Verify Lambda triggers are correct

For more details:

AWS

answered a year ago

  • Hello, Thank you for your answer. I am using serverless framework version "4" and there is no endpointType property for rest function: ('functions.rest.events.0.http': unrecognized property 'endpointType')

    I added the apiType: REGIONAL but it did not update the gateway to be REGIONAL.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.