10-example-upload-public.py 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # My IAM User inline policy is:
  2. #
  3. # {
  4. # "Version": "2012-10-17",
  5. # "Statement": [
  6. # {
  7. # "Effect": "Allow",
  8. # "Action": [
  9. # "s3:ListAllMyBuckets",
  10. # "s3:PutObject",
  11. # "s3:GetObject",
  12. # "s3:PutObjectAcl",
  13. # "s3:GetObjectAcl"
  14. # ],
  15. # "Resource": [
  16. # "arn:aws:s3:::*"
  17. # ]
  18. # }
  19. # ]
  20. # }
  21. import boto3
  22. from botocore.client import Config
  23. ACCESS_KEY_ID = ''
  24. ACCESS_SECRET_KEY = ''
  25. BUCKET_NAME = 'test-img-bucket-12131'
  26. FILE_NAME = 'bitmoji.png';
  27. data = open(FILE_NAME, 'rb')
  28. # S3 Connect
  29. s3 = boto3.resource(
  30. 's3',
  31. aws_access_key_id=ACCESS_KEY_ID,
  32. aws_secret_access_key=ACCESS_SECRET_KEY,
  33. config=Config(signature_version='s3v4')
  34. )
  35. # Image Uploaded
  36. s3.Bucket(BUCKET_NAME).put_object(Key=FILE_NAME, Body=data, ACL='public-read')
  37. print ("Done")