Amazon SageMaker Downloading Files from S3

Question:

I’m storing midi files in an S3 bucket and am trying to download them into the SageMake jupyter notebook. I am using this code

however I am getting An error occurred (403) when calling the HeadObject operation: Forbidden

Here are the permissions attached for the S3:

Answer:

The S3 bucket sagemakerbucketname you are using should be in the same region as the Sagemaker Notebook Instance.
The IAM role associated with the notebook instance should be given permission to access the S3 bucket.

Run below command in the sagemaker notebook to get the IAM role

role = get_execution_role()

Verify the role used to launch the notebook has permissions to access the S3 bucket. These are the permissions you are expected to have


{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::sagemakerbucketname"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::sagemakerbucketname/*"
]
}

Leave a Reply