Skip to content

Instantly share code, notes, and snippets.

@rpgreen
rpgreen / master.vm
Created Feb 23, 2016
API Gateway "Send Everything" Mapping Template
View master.vm
## API Gateway "Send Everything" Mapping Template - Ryan Green - ryang@ryang.ca
## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
#set($allParams = $input.params())
{
"body-json" : "$input.json('$')",
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
@rpgreen
rpgreen / Latency.java
Last active Dec 10, 2018
A simple script to measure API Gateway endpoint latency. Requires Apache HttpComponents
View Latency.java
@Test
public void testPerf() throws IOException {
final HttpGet request = new HttpGet("https://[API-ID].execute-api.[REGION].amazonaws.com/[STAGE]/[PATH]");
final int numRequests = 10000;
final int[] histogram = new int[100];
final List<Integer> latencies = new ArrayList<>();
final CloseableHttpClient client = HttpClients.createDefault();
for (int i = 0; i < numRequests; i++) {
@rpgreen
rpgreen / gist:c127aa4ebbcaa9026be7
Last active Dec 18, 2019
Swagger file demonstrating two ways to achieve HTTP redirects using API Gateway and Lambda
View gist:c127aa4ebbcaa9026be7
---
swagger: "2.0"
basePath: "/test"
schemes:
- "https"
paths:
/lambdaredirect-default:
get:
produces:
- "application/json"
@rpgreen
rpgreen / gist:5cd3d5c872781335a5d3
Last active Mar 3, 2020
An API Gateway mapping template to output all HTTP parameters in the JSON body
View gist:5cd3d5c872781335a5d3
#set($allParams = $input.params())
{
"body-json" : "$input.json('$')",
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
You can’t perform that action at this time.