Code Monkey home page Code Monkey logo

python-aws-s3's Introduction

python-aws-s3

About

This is a demo of setting up an Amazon Web Service (AWS) S3 bucket and uploading a file with Python.

Setting Up Bucket

Open AWS Console and log in.

alt text

Click the Services dropdown and select the S3 service.

alt text

alt text

Click Create Bucket. Give it a name, region then hit next through each step.

alt text

alt text

alt text

alt text

alt text

Now click your new bucket

alt text

Upload a test image to your bucket

alt text

alt text

alt text

alt text

You can find your new file. If you click it, you should see a link. Open the link in a new tab.

alt text

As you can see, you'll get "Access Denied".

alt text

Click the file, and under "more" press make public. Refresh the link.

alt text

alt text

alt text

Now click Services then go to IAM dashboard.

alt text

You should see your IAM dashboard. On the left menu, you can click Users.

alt text

alt text

Click the Add User.

alt text

alt text

alt text

alt text

alt text

Now click your new user from the list of users.

alt text

Copy the User ARN

alt text

Reopen the S3 dashboard

alt text

alt text

Now click the permissions tab.

alt text

Then click Bucket Policy.

alt text

alt text

Set your Bucket Policy to be the same as below. Change arn:aws:iam::281979644754:user/sample-user to be your User ARN. Also change arn:aws:s3:::img-bucket-00123 to your Bucket ARN. The bucket ARN is above the textarea.

{
    "Version": "2012-10-17",
    "Id": "Policy1488494182833",
    "Statement": [
        {
            "Sid": "Stmt1488493308547",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::281979644754:user/sample-user"
            },
            "Action": [
                "s3:ListBucket",
                "s3:ListBucketVersions",
                "s3:GetBucketLocation",
                "s3:Get*",
                "s3:Put*"
            ],
            "Resource": "arn:aws:s3:::img-bucket-00123"
        }
    ]
}

Click CORS configuration and add the following policy:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
  </CORSRule>
</CORSConfiguration>

Reopen the IAM dashboard.

alt text

Open your new user.

alt text

Click on the New inline policy

alt text

alt text

Update the policy to be as follows:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets",
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::*"
            ]
        }
    ]
}
git clone https://github.com/keithweaver/python-aws-s3.git
cd python-aws-s3
python example.py

alt text

python example-w-folder-create.py

alt text

python-aws-s3's People

Contributors

keithweaver avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.