AppSync向Lambda发送的事件请求可以在Lambda函数中使用event参数进行访问。该事件参数是一个包含AppSync请求的JSON对象。
以下是一个JSON示例,其中包含了一个使用GraphQL进行查询的AppSync请求:
{
"arguments": {
"input": {
"name": "John Doe",
"email": "johndoe@email.com"
}
},
"identity": {
"claims": {
"cognito:username": "johndoe"
},
"defaultAuthStrategy": "ALLOW"
},
"info": {
"fieldName": "createUser",
"parentTypeName": "Mutation",
"selectionSetList": [
"{",
" id",
" name",
" email",
" createdAt",
"}"
],
"selectionSetGraphQL": "{ id name email createdAt }",
"variables": {
"input": {
"name": "John Doe",
"email": "johndoe@email.com"
}
}
},
"request": {
"headers": {
"accept": "application/json",
"content-length": "197",
"content-type": "application/json",
"host": "xxxxx.appsync-api.us-west-2.amazonaws.com",
"x-amz-date": "20200101T000000Z",
"x-amz-security-token": "xxxxxxxx",
"x-api-key": "xxxxxxxx"
},
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"method": "POST",
"path": "/graphql",
"protocol": "HTTP/1.1"
},
"source": null,
"stash": {},
"typeName": "Mutation"
}
在Lambda函数中,可以使用以下方法来访问该事件请求:
exports.handler = async (event, context) => {
const request = event.request;
const authorizationHeader = request.headers.authorization;
const httpMethod = request.method;
// ...
}
上述示例代码中,我们可以通过访问event.request
对象来获取AppSync请求发送的