My scenario, I am trying to implement read AWS Stored S3 word document (.doc and .docx) file content from Aws Lambda by using python. Below code I am using, My problem is I can able to get the file name but I can't able to read content.
def lambda_handler(event, context):
file_contents = s3.Object(‘Bucketname’, 'sample.docx').get()['Body'].read().decode("unicode-escape")
return {
'File Name' : obj.key,
‘Content’ : file_contents
}
Response: { "errorMessage": "'unicodeescape' codec can't decode bytes in position 25818-25819: truncated \\xXX escape", "errorType": "UnicodeDecodeError", "stackTrace": [ [ "/var/task/lambda_function.py", 76, "lambda_handler", "file_contents = s3.Object('Bucketname', 'sample.docx').get()['Body'].read().decode(\\"unicode-escape\\")" ] ] }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.