📺 Develpreneur YouTube Episode

Video + transcript

Python - AWS - Create A Bucket

2023-10-19 •Youtube

Detailed Notes

We continue the series of tutorials as we build out a backup system that drops archive files into Amazon's S3 and related storage. This episode gets us started with the Boto3 library and AWS command line interface in a practical sense as we navigate creating a bucket in S3.

You can find out more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list and you will periodically receive coupons for courses as well as notifications of the latest releases.

Transcript Text
[Music]
uh in a sense oops let's flip back over
here and so I've got very simple
examples now all what we're going what
we're going to
do is we're going to go in here we're
going to do create a bucket and you can
find that as well so what I'm going to
do is let's just go ahead and Tack that
onto
it and so now what we're going to do is
we're going to come over
here and I'm going to put it because I'm
going to do some copy and paste because
that'll be a little easier to work in
the little place I'm working so uh here
let's see that's hello S3 I don't need
oh so now what I'm going to do is I'm
going to
do instead of hello S3 oh that was
already
there there we go there's the first
one and I want create oh because it
pushed it over on
me so now what I'm going to do is I'm
going to create a
bucket and um it's going to be a default
region uh if that works and and
then uh so I'm going to come in here I'm
going to
do uh so it's going to do oh so it's in
s. bucket name so I want to do this
I'm going have to give it
a bucket name let's see I don't need
region override uh I don't really need a
logger but we'll keep that
anyways let's go ahead and set that
up uh created
that if I look
[Music]
here
so what they've got here is they've got
a bucket and a name that they're using
we're going to just call it I think we
just want a bucket
right yeah bucket. name and bucket so
self.
bucket
um so do bucket
create which
is
oh it's a high Lev resource and build
that wraps actions in a class-like
structure so the bucket is going to
be um let's do
this well let's actually do it this way
we're just going to connect because
that's what we did before where did I go
uh we do the
hello we're going to do this
and let's see so
create and we're going to try
this and if we do that then that should
be okay if we region override we have to
worry about that uh region equals this
bucket we don't need a sell
let's just we're not going to worry
about a logger right now so we're going
to
print and we're going to print
here wh wow that totally got messed up
nice little typo okay print uh blah blah
blah bucket.
name and there we go so let's
see oh we don't need that to be
self and let's call this create
bucket so
now if we take
that let we go over
here and then what we're going to do is
we'll just paste that in so we've got to
create
bucket and then we're going to come in
here and we're going to call create
bucket
and we don't need an override oops we do
need a Comm up
there wonder if that typo came across
there
too uh that is bucket name
is create
that wait till exists created a bucket
in
region let's see if this will do what we
need it to otherwise I may have
to let's go back over here did that have
that Z yeah I
did so we need to take that and then we
also need this to
be that's going to be bucket uncore name
and let's see what we
do so we take this and now we're going
to create a bucket and we're going to
call it
um we're going to call it um our
backups
don't think it's going to like that
because bucket names have some issues
but we're going to find out in just a
second so if we try to run
it uh specified bucket is
not valid and so that's happening on the
bucket.
create and it's most
likely uh let's
see did it tell us uh client errors not
oh we've got something messed up there
oh let's just do
this let's just call it
error uh it couldn't do that let's see
if it's going to try to tell us where it
did see if we can do it this way is it
going to tell something little
different
nope oh I think that's going to be I
think we need that to be
exception oh we probably need the
errors because it probably isn't going
to like
that yeah there we go so I couldn't
create that bucket in that region oh
interesting oh our backups in East
one let's see why that couldn't be um um
we did
that oh CU it doesn't like that bucket
that's the
region so let's take a look real
quick uh we come in
here
so let's go look in the create
bucket so here we
go uh so there
is uh create bucket
bucket
oh that's in the API oh that is so it
should
be if we look at client. create
bucket uh so we probably want that so we
want
actually
um we probably
want
this
to be what we want there and then we
want
oops oh we've got
that okay so that's
[Music]
S3 uh s3.
create
actually we probably don't need that at
all and let's see there's region let's
do S3
dot uh what did we call that uh create
bucket is that the
[Music]
client
yeah so we want this to be
client which means create bucket that's
going to be
there
whoops and
then uh that needs to
be well it was getting it
so let's go back and look at
that okay
so let's do
this that's the bucket
create bucket.
name equals bucket
name
bucket. wait till
exists um that's probably
good uh is that going to work that
should be our create bucket
oh is it going to give us a client error
probably not
okay let's just do an
[Music]
exception
if we take that oh let's just do
this where'd it
go say
quit this is going to be create
bucket name is going to
be actually be let's do
DP um
tutorial
backup let's try
that so now if we run
it they have a required parameter not
set so the
name
here and it's there on
57 oh so there does need to be a name
okay
and then so we don't need
that and specified bucket is not valid
so let's go look at that real
quick um I
bet so if we go look then we're going to
find find that
uh let's try that
again um
yes I'm not a
robot let's try this
again
so here's ours it says create
bucket let's go look here oh let's take
this actually let's take all three of
these actually let's take this whole
section we just do it this
way we are going to steal that thing
and let's do it like
this
so that's really
our create bucket right yep bucket name
Regent so okay so
now let's see if this gives us something
a little
better uh that should
work so now if we run it there we go and
uh it still tells us that the specified
bucket is not
valid let's go look here
again Okay naming standards here we
go uh lowercase characters numbers
periods that's
probably so here's probably your issue
let's do
this and we're going to come in
here oh one too many of
those we're going do that so that we
know what our name's supposed to be so
now if we call it
here this is going to be um we're going
to call this
backup
repository oh tutorial
because you do need something sort of
complex so we're going to go with that
uh is that too long 3 and
63 uh each label cannot contain underst
stores in with a dash or can have
consecutive periods use dashes adjacent
to periods so we can do it like this so
we could call it uh where do we do
it this is probably the hardest part is
actually naming your bucket so let's do
that uh let's let's leave it to a
default and see if that works and then I
bet we
will and there we go and then
here is our
backup so it took a little bit of work
uh but we did get there so if we now see
wh if we do this and we just get rid of
the create because we're going to
actually drop this whole thing
anyways now we'll see here's our buckets
here and I think that's good enough for
now we're going to come back into the
next one sorry if we got a little bit
out of sorts I want to make sure it was
configured that is one of the things you
will run into sometimes the
configuration can be a little bit of a
pain but what you want to do is be able
to create your bucket because then the
next time we're going to come around
we're going to start actually putting
stuff into that we're going to grab
files and we're going to store them out
there hope this is helpful for you as
always shoot us an email at info
developer.com if you have any questions
other than that go out there and uh
check this stuff out so go have yourself
a great day a great week we will talk to
you next
[Music]
time
Transcript Segments
1.35

[Music]

27.679

uh in a sense oops let's flip back over

29.48

here and so I've got very simple

32.88

examples now all what we're going what

34.719

we're going to

35.719

do is we're going to go in here we're

37.8

going to do create a bucket and you can

39.12

find that as well so what I'm going to

41.239

do is let's just go ahead and Tack that

44.8

onto

46.039

it and so now what we're going to do is

48.96

we're going to come over

52.76

here and I'm going to put it because I'm

54.84

going to do some copy and paste because

56.359

that'll be a little easier to work in

58.16

the little place I'm working so uh here

61.359

let's see that's hello S3 I don't need

67.64

oh so now what I'm going to do is I'm

71.72

going to

74.6

do instead of hello S3 oh that was

77.88

already

82.36

there there we go there's the first

88.24

one and I want create oh because it

91.799

pushed it over on

95.96

me so now what I'm going to do is I'm

98.439

going to create a

100.479

bucket and um it's going to be a default

103.56

region uh if that works and and

106.6

then uh so I'm going to come in here I'm

109.119

going to

114.84

do uh so it's going to do oh so it's in

117.88

s. bucket name so I want to do this

120.719

I'm going have to give it

123.119

a bucket name let's see I don't need

126.52

region override uh I don't really need a

129.16

logger but we'll keep that

133.08

anyways let's go ahead and set that

138.8

up uh created

143.04

that if I look

145.02

[Music]

148.76

here

151.879

so what they've got here is they've got

153.72

a bucket and a name that they're using

155.56

we're going to just call it I think we

157.519

just want a bucket

159.92

right yeah bucket. name and bucket so

162.68

self.

166.28

bucket

169.319

um so do bucket

174.519

create which

178.76

is

182.319

oh it's a high Lev resource and build

183.84

that wraps actions in a class-like

185.28

structure so the bucket is going to

189.239

be um let's do

191.959

this well let's actually do it this way

194.76

we're just going to connect because

196.04

that's what we did before where did I go

199.36

uh we do the

206.4

hello we're going to do this

213.92

and let's see so

225.08

create and we're going to try

229.28

this and if we do that then that should

231.72

be okay if we region override we have to

234

worry about that uh region equals this

237.879

bucket we don't need a sell

241.959

let's just we're not going to worry

243.079

about a logger right now so we're going

244.319

to

247.36

print and we're going to print

251

here wh wow that totally got messed up

255

nice little typo okay print uh blah blah

257.639

blah bucket.

260.199

name and there we go so let's

264.44

see oh we don't need that to be

268.12

self and let's call this create

272.52

bucket so

275.56

now if we take

278.6

that let we go over

286.08

here and then what we're going to do is

289.4

we'll just paste that in so we've got to

291.039

create

292.16

bucket and then we're going to come in

294.6

here and we're going to call create

298.56

bucket

300.24

and we don't need an override oops we do

303.08

need a Comm up

318.16

there wonder if that typo came across

320.6

there

322.199

too uh that is bucket name

327.919

is create

333.039

that wait till exists created a bucket

335.72

in

344.199

region let's see if this will do what we

346.4

need it to otherwise I may have

357.28

to let's go back over here did that have

359.88

that Z yeah I

363.199

did so we need to take that and then we

367.56

also need this to

369.56

be that's going to be bucket uncore name

373.88

and let's see what we

375.44

do so we take this and now we're going

378.56

to create a bucket and we're going to

380

call it

382.44

um we're going to call it um our

388.4

backups

391.28

don't think it's going to like that

392.44

because bucket names have some issues

394.12

but we're going to find out in just a

395.479

second so if we try to run

399.199

it uh specified bucket is

402.72

not valid and so that's happening on the

406.12

bucket.

407.28

create and it's most

410.68

likely uh let's

413.039

see did it tell us uh client errors not

416.759

oh we've got something messed up there

420.879

oh let's just do

425.28

this let's just call it

432.28

error uh it couldn't do that let's see

435.16

if it's going to try to tell us where it

437.599

did see if we can do it this way is it

439.96

going to tell something little

441.68

different

448.319

nope oh I think that's going to be I

451

think we need that to be

454.199

exception oh we probably need the

456.759

errors because it probably isn't going

458.599

to like

463.199

that yeah there we go so I couldn't

466.28

create that bucket in that region oh

470.759

interesting oh our backups in East

476.08

one let's see why that couldn't be um um

480

we did

483.759

that oh CU it doesn't like that bucket

487.159

that's the

491.919

region so let's take a look real

495.879

quick uh we come in

508.24

here

510.68

so let's go look in the create

526.6

bucket so here we

529.48

go uh so there

532.44

is uh create bucket

538.2

bucket

542.76

oh that's in the API oh that is so it

545.12

should

545.88

be if we look at client. create

553.44

bucket uh so we probably want that so we

555.92

want

558.44

actually

562.36

um we probably

565.92

want

568.12

this

572.12

to be what we want there and then we

574.8

want

581.44

oops oh we've got

584.48

that okay so that's

587.64

[Music]

589.079

S3 uh s3.

598.12

create

601.32

actually we probably don't need that at

604.36

all and let's see there's region let's

611.959

do S3

615.399

dot uh what did we call that uh create

624.44

bucket is that the

626.15

[Music]

628.04

client

633.16

yeah so we want this to be

635.079

client which means create bucket that's

637.72

going to be

639.8

there

642.92

whoops and

644.839

then uh that needs to

658.04

be well it was getting it

662

so let's go back and look at

668.079

that okay

670.639

so let's do

673.56

this that's the bucket

679.88

create bucket.

683.24

name equals bucket

687.959

name

691.6

bucket. wait till

695.44

exists um that's probably

700.72

good uh is that going to work that

702.92

should be our create bucket

707.04

oh is it going to give us a client error

709.72

probably not

713.68

okay let's just do an

715.87

[Music]

717.959

exception

721.399

if we take that oh let's just do

724.56

this where'd it

729.639

go say

731.8

quit this is going to be create

735.32

bucket name is going to

741.04

be actually be let's do

747

DP um

749.839

tutorial

752.24

backup let's try

754.639

that so now if we run

759.36

it they have a required parameter not

762.24

set so the

765.72

name

772.76

here and it's there on

775.56

57 oh so there does need to be a name

778.12

okay

782.199

and then so we don't need

789.24

that and specified bucket is not valid

792.32

so let's go look at that real

797.519

quick um I

805.839

bet so if we go look then we're going to

808.519

find find that

834.36

uh let's try that

836.88

again um

846.48

yes I'm not a

854.839

robot let's try this

867.68

again

876.079

so here's ours it says create

881.759

bucket let's go look here oh let's take

884.72

this actually let's take all three of

886.72

these actually let's take this whole

888.36

section we just do it this

890.759

way we are going to steal that thing

895.16

and let's do it like

897.68

this

900.72

so that's really

902.839

our create bucket right yep bucket name

906.44

Regent so okay so

910.32

now let's see if this gives us something

912.519

a little

915.279

better uh that should

923.6

work so now if we run it there we go and

930.639

uh it still tells us that the specified

932.56

bucket is not

935.04

valid let's go look here

943.399

again Okay naming standards here we

946.399

go uh lowercase characters numbers

949.319

periods that's

950.88

probably so here's probably your issue

954.12

let's do

957.6

this and we're going to come in

962.36

here oh one too many of

965.72

those we're going do that so that we

967.759

know what our name's supposed to be so

970.319

now if we call it

974.04

here this is going to be um we're going

977.92

to call this

979.24

backup

985.44

repository oh tutorial

991.44

because you do need something sort of

993.48

complex so we're going to go with that

995.199

uh is that too long 3 and

998.12

63 uh each label cannot contain underst

1001.279

stores in with a dash or can have

1003.44

consecutive periods use dashes adjacent

1005.68

to periods so we can do it like this so

1009

we could call it uh where do we do

1012.56

it this is probably the hardest part is

1014.959

actually naming your bucket so let's do

1017.16

that uh let's let's leave it to a

1019.48

default and see if that works and then I

1022.959

bet we

1024.679

will and there we go and then

1028.72

here is our

1031.319

backup so it took a little bit of work

1034.039

uh but we did get there so if we now see

1037.919

wh if we do this and we just get rid of

1040.839

the create because we're going to

1043

actually drop this whole thing

1047.4

anyways now we'll see here's our buckets

1050.72

here and I think that's good enough for

1052.72

now we're going to come back into the

1054.2

next one sorry if we got a little bit

1056.6

out of sorts I want to make sure it was

1057.919

configured that is one of the things you

1059.4

will run into sometimes the

1060.679

configuration can be a little bit of a

1062.2

pain but what you want to do is be able

1064.08

to create your bucket because then the

1066.36

next time we're going to come around

1067.28

we're going to start actually putting

1068.32

stuff into that we're going to grab

1069.799

files and we're going to store them out

1071.12

there hope this is helpful for you as

1073.96

always shoot us an email at info

1075.559

developer.com if you have any questions

1078.48

other than that go out there and uh

1080.799

check this stuff out so go have yourself

1082.32

a great day a great week we will talk to

1084.76

you next

1089.86

[Music]

1103.64

time