-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload all my photos to a secure S3 bucket #4
Comments
Research thread: https://twitter.com/simonw/status/1249049694984011776
https://testdriven.io/blog/storing-django-static-and-media-files-on-amazon-s3/ looks useful |
I'm going to call my bucket |
https://console.aws.amazon.com/s3/bucket/create?region=us-west-1 I created it with no public read-write access. I plan to use signed URLs via a transforming proxy to access images for display on the web. |
Creating IAM groups called Now I can attach an "inline policy" to each one. For the read-write group I go here: https://console.aws.amazon.com/iam/home#/groups/dogsheep-photos-simon-read-write Example policies are here: https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html For the read-write one I went with: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::dogsheep-photos-simon/*"
]
}
]
} For the read-only policy I'm going to guess that this is appropriate: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject*",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::dogsheep-photos-simon/*"
]
}
]
} I tried the policy simulator to test this out: https://policysim.aws.amazon.com/home/index.jsp?#groups/dogsheep-photos-simon-read - this worked: |
Next step: create two IAM users, one for each of those groups. https://console.aws.amazon.com/iam/home#/users$new?step=details I copied the keys into a secure note in 1password. Couldn't get into Transmit with them though! https://library.panic.com/transmit/transmit5/iam-roles/ may help. |
I'm going to create another user just for Transmit, with full S3 access. name: Rather than creating a group for that user, I'm trying the "Attach existing policies directly" option: That user DID work with Transmit. I uploaded a test HEIC image. I used Transmit to copy a signed URL for it.
|
Next step: attempt a programmatic upload using the Also attempt a programmatic bucket listing and read using |
How about generating a signed URL? read_client.generate_presigned_url(
"get_object",
Params={
"Bucket": "dogsheep-photos-simon",
"Key": "this_is_fine.jpg",
},
ExpiresIn=600
) Which does this:
So it redirects to another URL... which returns this:
So that worked! It did come back with |
Running the upload again like this resulted in the correct content-type: client.upload_file(
"/Users/simonw/Desktop/this_is_fine.jpg",
"dogsheep-photos-simon",
"this_is_fine.jpg",
ExtraArgs={
"ContentType": "image/jpeg"
}
) |
This is great! I now have a key that can upload photos, and a separate key that can download photos OR generate signed URLs to access those photos. Next step: a script that starts uploading my photos. |
I'm going to start with this:
This will scan the provided directory (and all sub-directories) for image files. It will then:
Stretch goal: grab the EXIF data and include that in the |
Got this working! I'll do EXIF in a separate ticket #3. |
The text was updated successfully, but these errors were encountered: