Making Files Public

New Terms:

Permissions — A way of specifying who has access to your files, and how they can access them.

ACL — An acronym for “Access Control List”. It means essentially the same thing as permissions.

Permission Levels:

Bucket vs Object — Permissions can apply to your bucket as a whole, or to an individual object (file) in your bucket. Different files in the same bucket can have different permissions.

Read vs Write — Read permissions are about looking, but not touching. Write permissions are about making changes. For example, if you give everyone read permissions on a file in your bucket, then everyone can download it -- but they can’t change the file in your bucket. If you give everyone write permission on your bucket, then they can change the files in your bucket. (Giving write permissions to everyone is usually a bad idea!)

Object access vs Permission access — Object access refers to how the object (or bucket) can be read or written. Permission access refers to who is allowed to change permissions on the object (or bucket). Generally, you only want to modify object access, not permission access.

0:00

Uploading files to Amazon S3 is a great
way to keep backups of your important

0:04

private files.

0:05

But S3 can also share your files
with others, if you ask it to.

0:09

Have you ever tried to e-mail
a file to a friend and

0:11

gotten an error message
saying it's too large?

0:14

Instead, you can upload that file to S3,
make it publicly accessible, and

0:18

e-mail a link to it, so
that your friend can download it from S3.

0:22

And you can still keep your private
files secure at the same time.

0:26

To do that,
we use a concept called permissions.

0:29

It's sometimes also known as
Access Control Lists or ACLs.

0:33

The basic idea is,

0:35

if you own something, you can
decide how to share it with others.

0:39

When you're thinking about permissions,

0:40

it's generally useful to
think of it like a grid.

0:43

One axis is the who axis,
who do you want to share with?

0:48

The other axis is the how axis,
how can they share with you?

0:52

The simplest way to divide the who axis
is to lump everyone else into one group.

0:57

It's you against the world.

0:58

And the simplest way to divide the how
axis is to talk about reading data and

1:03

writing data.

1:05

This is how the permissions on
your S3 bucket look by default.

1:09

You are allowed to read and write data
in the Bucket, but no one else can.

1:13

In this case, writing data means modifying
the bucket, uploading new files,

1:18

moving files around, and deleting files.

1:20

There's also a different
set of permissions for

1:22

each individual file in a bucket.

1:24

However, file permissions are only
concerned with reading data,

1:28

not writing data.

1:29

Right now, the owner has all
the permissions and the world has none.

1:33

What happens if we change that?

1:35

If you give out the read permission for

1:37

the bucket, then others can see
which files are in the bucket, but

1:40

they can't actually download
any files from the bucket.

1:43

If you give out the read permission for

1:45

a file in the bucket, then others
will be able to download that file.

1:50

And if you give out the write permission
for the bucket, then others can modify

1:53

what's in the bucket, including uploading
new files or deleting existing files.

1:59

Be careful with giving out write
permissions, because you're still

2:02

responsible for paying AWS for
files that others upload into your bucket.

2:06

So let's see how we handle
these permissions in practice.

2:09

I'll open up my bucket, and you can see at
the top of the page there are four tabs,

2:13

Objects, Properties,
Permissions, and Management.

2:16

Objects are files and folders, and
we've seen how to handle those.

2:19

We're going to ignore Properties and
Management for now, and

2:21

click on Permissions.

2:23

You've got a grid here,
just like you saw earlier.

2:25

There are three options for
who can get permissions, treehouse,

2:28

that's me, any authenticated AWS user,
and everyone.

2:33

We're going to ignore that
any authenticated AWS user,

2:36

because it's basically a more
complicated form of the everyone option.

2:39

And for the how access,
we've got Read and Write for

2:42

both object access and permissions access.

2:45

Permissions access is the ability
to read and write permissions.

2:49

If you have the ability
to write permissions,

2:51

then you can give yourself and
others whatever permissions you'd like.

2:54

That's a powerful thing, but it's not
related to making files public, so

2:57

we're not going to talk
about it in this video.

2:59

For now, I'm not going to
make any changes to this tab.

3:02

Instead, I'm going to go
back to the Objects tab and

3:05

click on one of the files in the bucket.

3:06

When I open a file in a bucket,

3:08

you can see that there's
a Permissions tab here as well.

3:10

It looks the same, but it's for

3:12

permissions on the file
instead of on the bucket.

3:14

Just as we talked about earlier,
the write permission doesn't apply for

3:17

permissions on a file.

3:18

In order to write files
into the S3 bucket,

3:20

you need write permissions on the bucket,
not on the file.

3:23

The Read permissions is important though,

3:25

it determines whether people
can download the file.

3:28

Let's give it a try.

3:29

For now, we'll leave
the permissions at their defaults.

3:31

Notice that the Everyone group does
not have a read access to the file.

3:35

On the Overview tab,
there's a link to the file.

3:37

What happens if we open that link?

3:42

That doesn't look like
the treehouse logo at all.

3:44

Instead, S3 it's showing an error message,
Access Denied.

3:48

You see, I can download the file from S3
while I'm on the S3 Management console,

3:52

because on here, I'm logged in and
S3 knows who's asking for the file.

3:56

That link is a public
link that anyone can use.

3:59

S3 doesn't know that it's me, and so

4:01

it uses the everyone permissions to
determine if I can download the file.

4:06

As we just saw, the everyone group does
not have permission to read the file, so

4:10

S3 won't let me download
it using that public link.

4:13

But you may have noticed this
helpful looking Make public button,

4:16

while I was showing you around S3.

4:19

If I click that button, it's going to
change the permissions for me, Success.

4:24

Can you guess what changed?

4:26

Let's look back at the permissions tab.

4:27

Now the Everyone group
has read permissions, and

4:30

if I refresh that public link,
hey, it worked.

4:35

Now anyone can download this
file by using this link.

4:38

But what if you made
a file public by accident?

4:40

Well, that's easy to fix.

4:42

Just click on the Everyone group, and

4:43

then uncheck the read
permission under Object access.

4:48

Then Save and I'll refresh again.

4:53

Great, now it's private again,
just like it was before.

4:56

You can modify permissions
as much as you'd like.

4:59

There's one other nifty
thing I want to show you.

5:01

What if we change the permissions for the
bucket, instead of for an individual file?

5:05

I'll just go to my bucket permissions,

5:07

click on the Everyone group,
check the Read permission and click Save.

5:12

What did that do, I'll show you.

5:14

You see the structure of this URL?

5:16

It has the bucket name in it,
treehouse-course.

5:19

And it also has the filename in it,
image.png.

5:22

I'm going to take off the filename,
so we just have the bucket.

5:26

Now I'm getting a list of every
file that's in the bucket.

5:28

See, there is the image.png
file that we were looking at.

5:32

If you make this public, then anyone
can see what files are in the bucket,

5:35

although they may not be able to
download the files, of course.

5:38

If you don't want this
information to be public,

5:41

you can go back to the bucket
permissions and turn it off.

5:51

See, now the contents of your
bucket are private again.

5:55

S3 lets you store files privately or
share them with the world.

5:59

Permissions make it easy to specify
which files should be public and

6:02

which should be private, and fortunately,
if you make a mistake, it's easy to fix.

6:08

Making files public on S3 is a great
way to share them with others,

6:12

even files that are too
large to send via email.

6:15

There's a lot more you can do with
permissions, but that's a topic for