Skip to content

Instantly share code, notes, and snippets.

@rpgreen
Last active March 10, 2023 02:10
Show Gist options
  • Save rpgreen/c127aa4ebbcaa9026be7 to your computer and use it in GitHub Desktop.
Save rpgreen/c127aa4ebbcaa9026be7 to your computer and use it in GitHub Desktop.
Swagger file demonstrating two ways to achieve HTTP redirects using API Gateway and Lambda
---
swagger: "2.0"
basePath: "/test"
schemes:
- "https"
paths:
/lambdaredirect-default:
get:
produces:
- "application/json"
parameters: []
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers: {}
302:
description: "302 response"
headers:
Location:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "302"
responseParameters:
method.response.header.Location: "integration.response.body.location"
uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:[ACCOUNT_ID]:function:redirect-default/invocations"
httpMethod: "POST"
type: "aws"
/lambdaredirect-error:
get:
produces:
- "application/json"
parameters: []
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers: {}
302:
description: "302 response"
headers:
Location:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
https://.*:
statusCode: "302"
responseParameters:
method.response.header.Location: "integration.response.body.errorMessage"
responseTemplates:
application/json: "## intentionally blank"
uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:[ACCOUNT_ID]]:function:redirect-error/invocations"
httpMethod: "POST"
type: "aws"
securityDefinitions:
sigv4:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "awsSigv4"
definitions:
Empty:
type: "object"
--
Lambda Function "redirect-default":
--
exports.handler = function(event, context) {
context.succeed({
location : "https://example.com"
});
};
--
Lambda Function "redirect-error":
--
exports.handler = function(event, context) {
context.fail("https://example.com");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment