AWS S3 file upload access denied in php codeigniter - amazon-web-services

unable to upload files to aws s3 bucket shows "
A PHP Error was encountered
Severity: User Warning
Message: S3::putObject(): [AccessDenied] Access Denied
Filename: libraries/S3.php"

There are two ways to solve this problem-
If your Bucket permission "Bucket and object not public"
First, you need to change the permission in AWS S3
Go to Bucket->permission->edit
Uncheck
- Block new public ACLs and uploading public object
- Remove public access granted through public ACLs
Now try to upload, I hope it will work.
Use "S3::ACL_PRIVATE" in your putObjectFile function parameter at the time of upload file. ACL_PRIVATE and other keys are declared in the s3.php library file.
$saved = $this->s3->putObjectFile($file_path,
$this->bucket_name,
$this->folder_name.$s3_file,
S3::ACL_PRIVATE,
array(),
$mime_type);
Now try to upload.

Related

AWS S3 thumbnail "Access denied"

I followed Tutorial: Using an Amazon S3 trigger to create thumbnail images - AWS Lambda to create a thumbnail for my images.
However, when I try to access the images in bucket-resized I get an Access Denied.
That tutorial does not create 'public' objects.
If you want the resized objects to be public, you would either need to:
Create a Bucket Policy on the 'resized' bucket that grants s3:GetObject access for the bucket (see Bucket policy examples - Granting read-only permission to an anonymous user), OR
When uploading the object, use ACL='public-read', which will make the individual objects public
To make the bucket or objects public, you will also need to disable S3 Block Public Access on the bucket.
check if the thumbnail is generated successfully
check your bucket has public accessibility enabled
check if the generated file thumbnail has public read permission

What bucket permissions are required to download zip file directly from URL?

I am following a tutorial here and if I take this s3 URL from the tutorial, https://s3.eu-central-1.amazonaws.com/deepset.ai-farm-qa/datasets/documents/wiki_gameofthrones_txt.zip, I am able to directly download the zip file to local.
When I subsistute my own zip file URL, I get an error that BadZipFile: File is not a zip file, and if I try my URL for zip file, I get permission denied instead of being able to download.
I also confirmed the zip files are formated correctly using terminal: unzip -t zipfile.zip
What permissions do I need to change in s3 or on the s3 object to allow download of zip file directly from URL?
Still very new to IAM s3 permissions and current permission are the standard ones when creating bucket.
Objects in Amazon S3 are private by default. This means that they cannot be accessed by an anonymous URL (like you have shown).
If you want a specific object to be publicly available (meaning that anyone with the URL can access it), then use the Make Public option in the S3 management console. This can also be configured at the time that the object is uploaded by specifying ACL=public-read.
If you want a whole bucket, or particular paths within a bucket, to be public, then you can create a Bucket Policy that grants access to the bucket. This requires S3 Block Public Access to be disabled.
You can also generate n Amazon S3 pre-signed URL, which provides time-limited access to a private object. The pre-signed URL has additional information added that grants permission to access the private object. This is how web applications provide access to private objects to authorized users, such as photo websites.
If an object is accessed via an AWS API call or the AWS Command-Line Interface (CLI), then AWS credentials are used to identify the user. If the user has permission to access the object, then they can download it. This method uses an API call rather than a URL.
Two solutions:
Make your bucket/file public. Check this ( Not recommended)
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicRead",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject","s3:GetObjectVersion"],
"Resource":["arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"]
}
]
}
Use pre-signed URLs with SDK .. check this
var params = {Bucket: bucketname , Key: keyfile , Expires: 3600 , ResponseContentDisposition : `attachment; filename="filename.ext"` };
var url = s3.getSignedUrl('getObject', params);

Access denied to the bucket ******

I am new to AWS and i am trying to export VM images from AWS EC2 to S3 bucket that I had already imported using VMImport/Export service . I tried to export using AWS CLI and SDK (python) as well , but both returns the same error :
An error occurred (InvalidParameter) when calling the ExportImage operation: Access denied to the bucket ******23
Entered parameters are correct and i have given all public access to the S3 bucket used in Export action. Still the error continues to appear.
Any help would be greatly appreciated
Thanks in advance
I was facing the same issue , make sure the open the bucket and again give permission write read in S3 bucket as attached in image
Step 1Open your bucket s3 in console
step 2Go to permission tab
Step 3Make it public and ACL
Step 4Give the read write permissions
But best practice make IAM and add that account to permissions

AWS S3 Bucket Policy "Access Denied" while editing in web interface

I created a new S3 bucket through the web console, and I'm just trying to update the bucket policy, but i get an unhelpful error message:
"Error: Access denied"
Any ideas?
I needed to disable "Block public and cross-account access if bucket has public policies (Recommended)" in public access settings before updating the bucket policy
(For me) It works after I disabled Block new public bucket policies (Recommended) since it was a new public policy.

how to download an kms encrypted s3 object

I have created an s3 bucket with no policy and have uploaded a file with kms encryption . I have granted my ec2 instances full s3 access but still I'am not able to download the encrypted file(using aws CLI). it shows the following error: " An error occurred (AccessDenied) when calling the GetObject operation: Access Denied" but
I can download non-encrypted files from the same bucket with the same instance without any problem. Where am I gng wrong?
You also need to grant the instance access to the KMS key that was used to encrypt the file.