amazon-web-servicesamazon-s3aws-lambdareturnurl

How to get the URL of a file on AWS S3, return path without AWS Key


I need to use Lambda function ( Python), I need to get S3 path. It should look like this:

s3://some-path-to-the-location-of-generated-text/generated-text.txt

That URL client need to see in browser, without AWS Key, because presigned urls i don't need.

Thank you so much!


Solution

  • You need to use AWS S3 bucket policy which should allow read to all for given file.

    Your bucket policy should look like as follows:

     {
    
      "Statement":[
        {
          "Sid":"PublicRead",
          "Effect":"Allow",
          "Principal": "*",
          "Action":["s3:GetObject"],
          "Resource":["arn:aws:s3:::<name of bucket>/<file that you want everyone can read>"]
        }
    }
    

    Example - https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html#example-bucket-policies-use-case-2