AWS Lambda event, context

ewillwin·2022년 6월 20일
0

TSMtech Record

목록 보기
3/39

event object

The contents of the event parameter include all of the data and metadata your Lambda function needs to drive its logic. For example, an event created by API Gateway will contain details related to the HTTPS request that was made by the API client (for example, path, query string, request body)

Lambda Input Format

{
    "resource": "Resource path",
    "path": "Path parameter",
    "httpMethod": "Incoming request's method name"
    "headers": {String containing incoming request headers}
    "multiValueHeaders": {List of strings containing incoming request headers}
    "queryStringParameters": {query string parameters }
    "multiValueQueryStringParameters": {List of query string parameters}
    "pathParameters":  {path parameters}
    "stageVariables": {Applicable stage variables}
    "requestContext": {Request context, including authorizer-returned key-value pairs}
    "body": "A JSON string of the request payload."
    "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encoded"
}

Lambda Output Format

{
  "message": "Hello me!",
    "multiValueHeaders":{
      'Accept':[
        "*/*"
      ],
      // 중략..
    },
  "pathParameters": {
    "proxy": "hello/world"
  },
  "requestContext": {
    "accountId": "12345678912",
    "resourceId": "rofjd2",
    "stage": "testStage",
    "requestId": "deef4898-7610-11e6-8f14-25afc3e9ae23",
    "identity": {
      "cognitoIdentityPoolId": null,
      "accountId": null,
// 중략
      "sourceIp": "192.168.0.1",
      "user": null
    },
    "resourcePath": "/{proxy+}",
    "httpMethod": "GET",
    "apiId": "gy415nuk2l"
  },
  "body": "{\r\n\t\"a\": 1\r\n}",
  "isBase64Encoded": false
}

Lambda Return Format

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
// header: 단일 값 헤더만 (값이 오로지 1)
    "headers": { "headerName": "headerValue", ... },
// multiValueHeaders: 값이 여러개
// header, multiValueHeaders 모두 지정했을 경우 multiValueHeaders 값만 표시
    "multiValueHeaders": { "headerName": ["headerValue", "headerValue2", ...], ... },
    "body": "..."
}

event is the data that's passed to the function upon execution. In the previous chapter, we used the console to create a test event to be passed to the Lambda Fucntion.

context is a Python objects that implements methods and has attributes It's main role is to provide information about the current execution environment. Unlike event, the methods and properties of the context object remain the same regardless of the lambda was invoked or triggered.

profile
Software Engineer @ LG Electronics

0개의 댓글