-
-
Save 3mard/d7a6dcbdd390038120aa1bdf2599f665 to your computer and use it in GitHub Desktop.
Swagger file demonstrating two ways to achieve HTTP redirects using API Gateway and Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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