Bird
0
0

You want to add a new field requestTime with the current timestamp to every request sent to your backend using request mapping. Which mapping template snippet correctly adds this field?

hard📝 Best Practice Q15 of 15
AWS - API Gateway
You want to add a new field requestTime with the current timestamp to every request sent to your backend using request mapping. Which mapping template snippet correctly adds this field?
A{ "user": "$input.path('$.user')", "requestTime": "$context.stage" }
B{ "user": "$input.path('$.user')", "requestTime": "$input.requestTime" }
C{ "user": "$input.path('$.user')", "requestTime": "$stageVariables.requestTime" }
D{ "user": "$input.path('$.user')", "requestTime": "$context.requestTime" }
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to get current request time

    In API Gateway mapping templates, $context.requestTime provides the current request timestamp.
  2. Step 2: Check each option for correct usage

    { "user": "$input.path('$.user')", "requestTime": "$context.requestTime" } uses $context.requestTime correctly; others use invalid or unrelated variables.
  3. Final Answer:

    { "user": "$input.path('$.user')", "requestTime": "$context.requestTime" } -> Option D
  4. Quick Check:

    Use $context.requestTime for current timestamp [OK]
Quick Trick: Use $context.requestTime to add current timestamp in mapping [OK]
Common Mistakes:
  • Using $input.requestTime which doesn't exist
  • Confusing stage variables with request time
  • Using unrelated context variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes