Skip to content

Instantly share code, notes, and snippets.

@rpgreen
rpgreen / master.vm
Created February 23, 2016 00:02
API Gateway "Send Everything" Mapping Template
## 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 December 10, 2018 19:33
A simple script to measure API Gateway endpoint latency. Requires Apache HttpComponents
@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 March 10, 2023 02:10
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"
@rpgreen
rpgreen / gist:5cd3d5c872781335a5d3
Last active March 3, 2020 09:41
An API Gateway mapping template to output all HTTP parameters in the JSON body
#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