我有一个aws lambda函数,该函数会将位于s3存储桶中的dicom图像上载到第三方服务器,并检索响应。 我如何使用pytest模拟来模拟我的lambda函数 ?
答案 0 :(得分:1)
您可以将以下对象用作模拟对象
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"
}
}
}
]
}
,然后使用事件调用lamda函数,并为上下文调用null
lamda_function(event,null)
您可以找到更多的lamda事件模板here