Testing the Lambda function

Now that we have the Lambda code deployed, we can test that it is working correctly in the AWS Management Console. Perform the following steps:

  1. Sign in to the AWS Management Console and open the AWS Lambda console at https://console.aws.amazon.com/lambda/.
  2. In the AWS Lambda navigation pane, choose Functions.
  3. Choose lambda-dynamo-data-api.
  4. Choose Test.
  5. In Configure test event, under Event name, type requestApiGatewayGetValid and type or copy and paste the following code in the JSON document, overwriting the old code:
      {
"body": "{"test":"body"}",
"resource": "/{proxy+}",
"requestContext": {
"resourceId": "123456",
"apiId": "1234567890",
"resourcePath": "/{proxy+}",
"httpMethod": "GET",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"accountId": "123456789012",
"identity": {
"apiKey": null,
"userArn": null,
"cognitoAuthenticationType": null,
"caller": null,
"userAgent": "Custom User Agent String",
"user": null, "cognitoIdentityPoolId": null,
"cognitoIdentityId": null,
"cognitoAuthenticationProvider": null,
"sourceIp": "127.0.0.1",
"accountId": null
},
"stage": "prod"
},
"queryStringParameters": {
"StartDate": "20171009"
},
"headers": {
"Via": "1.1 08f323deadbeefa7af34e5feb414ce27
.cloudfront.net (CloudFront)",
"Accept-Language": "en-US,en;q=0.8",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Mobile-Viewer": "false",
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
"CloudFront-Viewer-Country": "US", "Accept":
"text/html,application/xhtml+xml,application/xml;q=0.9,
image/webp,/;q=0.8",
"Upgrade-Insecure-Requests": "1",
"X-Forwarded-Port": "443", "Host": "1234567890
.execute-api.us-east-1.amazonaws.com",
"X-Forwarded-Proto": "https",
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-
9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
"CloudFront-Is-Tablet-Viewer": "false",
"Cache-Control": "max-age=0",
"User-Agent": "Custom User Agent String",
"CloudFront-Forwarded-Proto": "https", "Accept-Encoding":
"gzip, deflate, sdch"
},
"pathParameters": {
"proxy": "path/to/resource"
},
"httpMethod": "GET",
"stageVariables": {
"baz": "qux"
},
"path": "/path/to/resource/324"
}
  1. The following are some important sections of the API Gateway GET request JSON:
    • The request uses the GET method from "httpMethod": "GET"
    • The resource or EventID is 324 and comes from "path": "/path/to/resource/324"
    • The query parameters come from "queryStringParameters": { "StartDate": "20171009"}
  2. Choose Create.
  3. Choose Test to run the test.

You should see from the execution results that the test succeeded with the sample API Gateway GET request. This includes the duration, memory used, and log output. Expand the details to see the response that will be sent to DynamoDB. It should be something like the following code:

{
"statusCode": "200",
"body": "[{"EventCount": 3, "EventDay": 20171001, "EventId":
"324"}]",
"headers": { "Content-Type": "application/json", "Access-Control-
Allow-Origin": "*"
}
}

If there is an error, check the Log Output for details, it could be something to do with the IAM role/policy, DynamoDB name, or the Lambda code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset