#要点
・GASでpostする時は 'contentType': 'application/json'
を指定してpayloadのjsonをstringifyしておく
・AWS側でparse
#コード
GoogleAppsScript
uploadToAws.gas
function uploadToAws() {
const aws_url = "APIのURL"
const params = {
'method' : 'post', //get or post
'contentType': 'application/json',
'payload' : JSON.stringify({"data1": "hogehoge" })
};
const req = UrlFetchApp.fetch(aws_url, params);
Logger.log(req.getContentText());
}
Lambda(Node.js)
lambdaSample.js
const aws = require('aws-sdk');
exports.handler = async (event) => {
const data = (event.requestContext.http.method === "GET") ? event.queryStringParameters
: (event.requestContext.http.method === "POST") ? JSON.parse(event.body)
: null;
const response = {
statusCode: (data) ? 200 : 503,
body: JSON.stringify((data) ? data.data1 : "no_data"),
};
return response;
};