Skip to content

Example of how to implement redirects in the Serverless framework

Notifications You must be signed in to change notification settings

GorillaStack/serverless-redirect-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-redirect-example

We just started playing with the v1 of the serverless framework after building a serverless hipchat plugin boilerplate repository and an example plugin that aggregates CloudWatch Alarms in version 0.5.6 of the serverless framework.

This is a simple serverless project designed to demonstrate the new way of achieving redirects in v1 of the serverless framework.

The old way:

Configure the response headers in the s-function.json file for your function.

Enter header configuration

  {
      "path": "uninstalled",
      "method": "GET",
      "type": "AWS",
      "authorizationType": "none",
      "authorizerFunction": false,
      "apiKeyRequired": false,
      "requestParameters": {},
      "requestTemplates": {
        "application/json": "$${defaultEndpoint}"
      },
      "responses": {
        "400": {
          "statusCode": "400"
        },
        "default": {
          "statusCode": "302",
          "responseParameters": {
            "method.response.header.Location": "integration.response.body.location"
          },
          "responseTemplates": {
            "application/json;charset=UTF-8": ""
          }
        }
      }
    }

The new way:

It appears that there is no longer a s-function.json file in v1 of the Serverless framework. Now we configure the response from the code directly.

'use strict';

module.exports.redirect = (event, context, callback) => {
  const response = {
    statusCode: 301,
    headers: {
      Location: 'https://www.gorillastack.com',
    },
    body: '',
  };

  callback(null, response);
};

About

Example of how to implement redirects in the Serverless framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published