-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrear_bucket.py
More file actions
44 lines (37 loc) · 900 Bytes
/
crear_bucket.py
File metadata and controls
44 lines (37 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import boto3
import logging
sessao = boto3.Session(profile_name="auto-curso")
cliente_s3 = sessao.client("s3")
nome_backet = "bucket-boto3-curso"
try:
# Criando o bucket
resposta_bucket = cliente_s3.create_bucket(
Bucket=nome_backet,
CreateBucketConfiguration={
"LocationConstraint": "us-east-2"
}
)
# imprimindo a resposta retornada
print(resposta_bucket)
except Exception as err: # noqa F841
logging.error("Este bucket já existe!")
# Enviando uma imagem para o bucket
cliente_s3.upload_file(
"arquivos/Amazon_Lambda_architecture_logo.svg",
nome_backet,
"imagens/logo_aws.svg"
)
# Criando uma documento dentro do próprio bucket
planilha = """
Nome\tNota
Ana\t9
Maria\t9
Pedro\t7
Carlos\t8
Marta\t10
"""
cliente_s3.put_object(
Body=planilha,
Bucket=nome_backet,
Key="planilha.xls"
)