Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Created August 13, 2015 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7kamura/2a42ea3ad37d703a8597 to your computer and use it in GitHub Desktop.
Save r7kamura/2a42ea3ad37d703a8597 to your computer and use it in GitHub Desktop.
{
"json": $input.json('$.*'),
"accountId": "$context.identity.accountId",
"allParams": "$input.params()",
"apiId": "$context.apiId",
"apiKey": "$context.identity.apiKey",
"caller": "$context.identity.caller",
"headerParams": "$input.params().header",
"httpMethod": "$context.httpMethod",
"pathParams": "$input.params().path",
"queryParams": "$input.params().querystring",
"requestId": "$context.requestId",
"resourceId": "$context.resourceId",
"resourcePath": "$context.resourcePath",
"sourceIp": "$context.identity.sourceIp",
"stage": "$context.stage",
"user": "$context.identity.user",
"userAgent": "$context.identity.userAgent",
"userArn": "$context.identity.userArn"
}
@r7kamura
Copy link
Author

こうなる

{
  json: [ ],
  accountId: "",
  allParams: "{path={}, querystring={}, header={Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8, Accept-Encoding=gzip, Accept-Language=ja,en-US;q=0.8,en;q=0.6, Cache-Control=max-age=0, CloudFront-Forwarded-Proto=https, CloudFront-Is-Desktop-Viewer=true, CloudFront-Is-Mobile-Viewer=false, CloudFront-Is-SmartTV-Viewer=false, CloudFront-Is-Tablet-Viewer=false, CloudFront-Viewer-Country=JP, Upgrade-Insecure-Requests=1, Via=1.1 202cfb2009dc7f4ad490fba3b77709c0.cloudfront.net (CloudFront), X-Amz-Cf-Id=B1K6UwdNQ2kJp3rswNNBiPUkH65NcMdCvsinxXJi45gNHMcqxFb0oA==, X-Forwarded-For=218.42.217.86, 205.251.214.81, X-Forwarded-Port=443, X-Forwarded-Proto=https}}",
  apiId: "os92ef4zmf",
  apiKey: "",
  caller: "",
  headerParams: "{Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8, Accept-Encoding=gzip, Accept-Language=ja,en-US;q=0.8,en;q=0.6, Cache-Control=max-age=0, CloudFront-Forwarded-Proto=https, CloudFront-Is-Desktop-Viewer=true, CloudFront-Is-Mobile-Viewer=false, CloudFront-Is-SmartTV-Viewer=false, CloudFront-Is-Tablet-Viewer=false, CloudFront-Viewer-Country=JP, Upgrade-Insecure-Requests=1, Via=1.1 202cfb2009dc7f4ad490fba3b77709c0.cloudfront.net (CloudFront), X-Amz-Cf-Id=B1K6UwdNQ2kJp3rswNNBiPUkH65NcMdCvsinxXJi45gNHMcqxFb0oA==, X-Forwarded-For=218.42.217.86, 205.251.214.81, X-Forwarded-Port=443, X-Forwarded-Proto=https}",
  httpMethod: "GET",
  pathParams: "{}",
  queryParams: "{}",
  requestId: "2c466721-41dc-11e5-bbde-9fb9e4e2dc23",
  resourceId: "2x33sn",
  resourcePath: "/echo",
  sourceIp: "218.42.217.86",
  stage: "production",
  user: "",
  userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36",
  userArn: ""
}

@r7kamura
Copy link
Author

{...} みたいになってるやつJSONっぽくしたい…

@r7kamura
Copy link
Author

@r7kamura
Copy link
Author

map風のデータ構造には .keySet が実行できるらしい

@r7kamura
Copy link
Author

@r7kamura
Copy link
Author

@r7kamura
Copy link
Author

勝った感じがある

{
  "json": $input.json('$.*'),
  "accountId": "$context.identity.accountId",
  "allParams": "$input.params()",
  "apiId": "$context.apiId",
  "apiKey": "$context.identity.apiKey",
  "caller": "$context.identity.caller",
  "headerParams": {
#foreach( $key in $input.params().header.keySet() )
    "$key": "$input.params().header.get($key)"#if( $foreach.hasNext ),#end
#end
  },
  "httpMethod": "$context.httpMethod",
  "pathParams": "$input.params().path",
  "queryParams": "$input.params().querystring",
  "requestId": "$context.requestId",
  "resourceId": "$context.resourceId",
  "resourcePath": "$context.resourcePath",
  "sourceIp": "$context.identity.sourceIp",
  "stage": "$context.stage",
  "user": "$context.identity.user",
  "userAgent": "$context.identity.userAgent",
  "userArn": "$context.identity.userArn"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment