I am running my application in an AWS AMI. The AMI is launched via a cloud formation template that creates AWS::IAM::Role
role with sts:AssumeRole
. Once the EC2 instance is up, I create an S3 bucket from the Ec2 instance using boto3.create_bucket
.
In my application I upload a file to the created bucket with encryption flag on. But while uploading I'm getting an error:
com.amazonaws.services.s3.model.AmazonS3Exception: x-amz-server-side-encryption header is not supported for this operation. (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: 04DD9259D04F92CA), S3 Extended Request ID: EVdqFn6jUNshxUejZFWa6VN/lHPXHyi0F+TG+UZ3K9Sh8Gy0MPABi1AnxZloIajypLb39/5UAVA=
This is the server side encryption part of my code:
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(contentLength);
meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION)
What am I doing wrong? This works as expected when I run my code elsewhere and use an S3 bucket. Is this somehow tied to cloud formation or sts:AssumeRole
?