# Get the object from the event and show its content type bucket = event['Records'][0]['s3']['bucket']['name'] key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') try: response = s3.get_object(Bucket=bucket, Key=key) print("CONTENT TYPE: " + response['ContentType']) return response['ContentType'] except Exception as e: print(e) print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) raise e
Response { "errorMessage": "An error occurred (AccessDenied) when calling the GetObject operation: Access Denied", "errorType": "ClientError", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 23, in lambda_handler\n raise e\n", " File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n response = s3.get_object(Bucket=bucket, Key=key)\n", " File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n" ] }
Function Logs START RequestId: d2b2a1b0-db50-49d4-acf8-41e58ce880c3 Version: $LATEST An error occurred (AccessDenied) when calling the GetObject operation: Access Denied Error getting object content from bucket my-test-bucket. Make sure they exist and your bucket is in the same region as this function. [ERROR] ClientError: An error occurred (AccessDenied) when calling the GetObject operation: Access Denied Traceback (most recent call last): File "/var/task/lambda_function.py", line 23, in lambda_handler raise e File "/var/task/lambda_function.py", line 17, in lambda_handler response = s3.get_object(Bucket=bucket, Key=key) File "/var/runtime/botocore/client.py", line 391, in _api_call return self._make_api_call(operation_name, kwargs) File "/var/runtime/botocore/client.py", line 719, in _make_api_call raise error_class(parsed_response, operation_name) END RequestId: d2b2a1b0-db50-49d4-acf8-41e58ce880c3 REPORT RequestId: d2b2a1b0-db50-49d4-acf8-41e58ce880c3 Duration: 966.62 ms Billed Duration: 967 ms Memory Size: 128 MB Max Memory Used: 71 MB Init Duration: 452.77 ms