用于lambda的aws实用程序
aws-utils-for-lambda的Python项目详细描述
用于lambda的aws实用程序
- BOTO3包装纸
- 优雅地处理异常并返回结构化响应
- 可与BOTO3包装一起用于Lambda层
安装
pip install -U aws-utils-for-lambda
请求
importaws_utilsaws_utils.s3.get_object('bucket_name','test_data.json',output_format='dict')
响应(dict)
{'data':'data','success':True,'output_format':'dict','error':"ClientError",'error_message':'error_message','full_response':'full_response','short_traceback':'short_traceback','full_traceback':'full_traceback'}
工作原理
编辑图表link
当前支持
- S3号
- 上传文件
- 获取对象
- 发电机
- 获取物品
- 放置物品
示例1
- 上传文件
- 获取对象
- 获取物品
- 放置物品
获取S3对象-请求:
importaws_utilsresponse=aws_utils.s3.get_object('bucket_name','test_data.json',output_format='dict')print(response)
获取s3对象-响应:
{'data':'{\n "name": "name",\n "age": "24",\n "country": "India"\n}','success':True,'output_format':'dict','error':None,'error_message':None,'full_response':{'ResponseMetadata':{'RequestId':'xxxxxxxxxxxx','HostId':'xxxxxxxxxxxx','HTTPStatusCode':200,'HTTPHeaders':{'x-amz-id-2':'xxxxxxxxxxxx','x-amz-request-id':'xxxxxxxxxxxx','date':'Sun, 26 May 2019 10:04:23 GMT','last-modified':'Sun, 26 May 2019 10:04:18 GMT','etag':'"xxxxxxxxxxxx"','accept-ranges':'bytes','content-type':'application/json','content-length':'65','server':'AmazonS3'},'RetryAttempts':0},'AcceptRanges':'bytes','LastModified':datetime.datetime(2019,5,26,10,4,18,tzinfo=tzutc()),'ContentLength':65,'ETag':'"xxxxxxxxxxxx"','ContentType':'application/json','Metadata':{},'Body':"<botocore.response.StreamingBodyat0x10591111>"},'short_traceback':None,'full_traceback':None}
示例2
获取S3对象-请求:
importaws_utilsresponse=aws_utils.s3.get_object('bucket_name','test_data.json',output_format='dict')print(response)
获取s3对象-响应:
{'data':None,'success':False,'output_format':'dict','error':'NoSuchKey','error_message':'An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.','full_response':None,'short_traceback':[' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/aws_utils/s3.py" line 26, in get_object\n full_response = s3.meta.client.get_object(Bucket=bucket, Key=file_path)\n',' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call\n return self._make_api_call(operation_name, kwargs)\n',' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call\n raise error_class(parsed_response, operation_name)\n'],'full_traceback':['Traceback (most recent call last):\n',' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/aws_utils/s3.py", line 26, in get_object\n full_response = s3.meta.client.get_object(Bucket=bucket, Key=file_path)\n',' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call\n return self._make_api_call(operation_name, kwargs)\n',' File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call\n raise error_class(parsed_response, operation_name)\n','botocore.errorfactory.NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.\n']}