4

I have a aws lambda function which will upload a dicom image located in an s3 bucket to a 3rd party server and retrieved the response. How do I mock my lambda function using pytest mock ?

Sarga
  • 149
  • 3
  • 16

1 Answers1

1

You can use the following object as a mock object

event = {
      "Records": [
        {
          "eventVersion": "2.0",
          "eventSource": "aws:s3",
          "awsRegion": "us-east-1",
          "eventTime": "2016-09-25T05:15:44.261Z",
          "eventName": "ObjectCreated:Put",
          "userIdentity": {
            "principalId": "AWS:AROAW5CA2KAGZPAWYRL7K:cli"
          },
          "requestParameters": {
            "sourceIPAddress": "222.24.107.21"
          },
          "responseElements": {
            "x-amz-request-id": "00093EEAA5C7G7F2",
            "x-amz-id-2": "9tTklyI/OEj4mco12PgsNksgxAV3KePn7WlNSq2rs+LXD3xFG0tlzgvtH8hClZzI963KYJgVnXw="
          },
          "s3": {
            "s3SchemaVersion": "1.0",
            "configurationId": "151dfa64-d57a-4383-85ac-620bce65f269",
            "bucket": {
              "name": "service-1474780369352-1",
              "ownerIdentity": {
                "principalId": "A3QLJ3P3P5QY05"
              },
              "arn": "arn:aws:s3:::service-1474780369352-1"
            },
            "object": {
              "key": "object",
              "size": 11,
              "eTag": "5eb63bbbe01eetd093cb22bb8f5acdc3",
              "sequencer": "0057E75D80IA35C3E0"
            }
          }
        }
      ]
    }

and then call the lamda function with the event and null for the context

lamda_function(event,null)

You can find more lamda event templates here

Ghonima
  • 2,978
  • 2
  • 14
  • 23