I’m trying to get a DeepLens Lambda function to upload an image to S3. I got the code for uploading from this tutorial.
def write_image_to_s3(img):
session = Session()
s3 = session.create_client('s3')
file_name = 'DeepLens/face.jpg'
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
_, jpg_data = cv2.imencode('.jpg', img, encode_param)
response = s3.put_object(ACL='public-read-write', Body=jpg_data.tostring(),Bucket='MY-BUCKET-NAME',Key=file_name)
image_url = 'https://s3.amazonaws.com/MY-BUCKET-NAME/'+file_name
return image_url
However, I keep getting the error:
Error in face detection lambda: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
I made an IAM role and attached it to the Deeplens lambda function and attached the following policies: AWSDeepLensLambdaFunctionAccessPolicy, AWSLambdaExecute, AWSDeepLensServiceRolePolicy, AmazonS3FullAccess, and a custom policy with the following JSON:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::MY-BUCKET-NAME”,
"arn:aws:s3:::MY-BUCKET-NAME/*"
]
}
]
}
I even gave the bucket public access through the access control list:
and made the bucket policy public:
{
"Version": "2012-10-17",
"Id": "Policy1534108093104",
"Statement": [
{
"Sid": "Stmt1534108083533",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::MY-BUCKET-NAME”
}
]
}
(I know it's a bad idea to make buckets public)
I looked at this and this and yet I’m still getting the AccessDenied error.