AWS series XII: DynamoDB
AWS series XII: DynamoDB
Serie de artigos sobre Amazon Web Services.
Lab 8 - AWS DynamoDB
Em este lab sobre DynamoDB aprenderemos alguns conceitos importantes na criação de DBaaS NoSQL:
- Criação de tabelas
- Inserção/consulta de dados via console
- Inserção/consulta via código
python
Aproveitaremos para ver alguns conceitos importantes sobre Identity and Access Management (IAM):
- Autenticação usando arquivo de credenciais
- Autenticação usando roles
Aproveitaremos também para mostrar as três formas de interação com a AWS:
- Console WEB
- Command line (comando
aws) - SDK Python (biblioteca
python3-boto3)
Pre-reqs
Uma VM com a imagem
Amazon LinuxNo console da AWS Academy, accessar as credenciais da conta para acesso programático:

- Copiar as credenciais no arquivo
~/.aws/credentialsdentro da VM:1 2 3 4 5
$ cat ~/.aws/credentials [default] aws_access_key_id=<copy here> aws_secret_access_key=<copy here> aws_session_token=<copy here>
- Configuramos a região correta (ignorar o resto dos campos):
1 2 3 4 5
$ aws configure AWS Access Key ID [****************Q5QG]: AWS Secret Access Key [****************aqWs]: Default region name [None]: us-east-1 Default output format [None]:
- Listar VMs (em formato
json):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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
$ aws ec2 describe-instances { "Reservations": [ { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0914bc04e5495b889", "InstanceId": "i-0eea6b50a48d07613", "InstanceType": "t2.micro", "LaunchTime": "2020-09-18T00:17:13.000Z", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "", "ProductCodes": [], "PublicDnsName": "", "State": { "Code": 48, "Name": "terminated" }, "StateTransitionReason": "User initiated (2020-09-20 20:10:17 GMT)", "Architecture": "x86_64", "BlockDeviceMappings": [], "ClientToken": "cb65d27a-49cb-d46d-a7ca-1b8368d22330", "EbsOptimized": false, "EnaSupport": true, "Hypervisor": "xen", "NetworkInterfaces": [], "RootDeviceName": "/dev/xvda", "RootDeviceType": "ebs", "SecurityGroups": [], "StateReason": { "Code": "Client.UserInitiatedShutdown", "Message": "Client.UserInitiatedShutdown: User initiated shutdown" }, "Tags": [ { "Key": "aws:cloudformation:stack-id", "Value": "arn:aws:cloudformation:us-east-1:440730077537:stack/awseb-e-32fei49nnj-stack/35d81f30-f944-11ea-9cb6-0eb23bbe71c5" }, { "Key": "elasticbeanstalk:environment-id", "Value": "e-32fei49nnj" }, { "Key": "Name", "Value": "Fiapapp-env" }, { "Key": "aws:cloudformation:stack-name", "Value": "awseb-e-32fei49nnj-stack" }, { "Key": "elasticbeanstalk:environment-name", "Value": "Fiapapp-env" }, { "Key": "aws:autoscaling:groupName", "Value": "awseb-e-32fei49nnj-stack-AWSEBAutoScalingGroup-17NY3APZ43NN7" }, { "Key": "aws:cloudformation:logical-id", "Value": "AWSEBAutoScalingGroup" } ], "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 1 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "HibernationOptions": { "Configured": false }, "MetadataOptions": { "State": "pending", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled" } } ], "OwnerId": "440730077537", "RequesterId": "940372691376", "ReservationId": "r-04e5222922400810c" }, { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0817d428a6fb68645", "InstanceId": "i-02a7e6dfe99d1f769", "InstanceType": "t2.micro", "KeyName": "fiap", "LaunchTime": "2020-09-20T20:11:49.000Z", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-1a", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-172-31-40-37.ec2.internal", "PrivateIpAddress": "172.31.40.37", "ProductCodes": [], "PublicDnsName": "ec2-18-232-70-66.compute-1.amazonaws.com", "PublicIpAddress": "18.232.70.66", "State": { "Code": 16, "Name": "running" }, "StateTransitionReason": "", "SubnetId": "subnet-17a00f48", "VpcId": "vpc-7166990c", "Architecture": "x86_64", "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "AttachTime": "2020-09-20T20:11:49.000Z", "DeleteOnTermination": true, "Status": "attached", "VolumeId": "vol-0b8b82a6443e712cf" } } ], "ClientToken": "", "EbsOptimized": false, "EnaSupport": true, "Hypervisor": "xen", "NetworkInterfaces": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-18-232-70-66.compute-1.amazonaws.com", "PublicIp": "18.232.70.66" }, "Attachment": { "AttachTime": "2020-09-20T20:11:49.000Z", "AttachmentId": "eni-attach-00f1dc9a09492b219", "DeleteOnTermination": true, "DeviceIndex": 0, "Status": "attached" }, "Description": "", "Groups": [ { "GroupName": "launch-wizard-3", "GroupId": "sg-0976be2478d3b8b08" } ], "Ipv6Addresses": [], "MacAddress": "0e:6a:4f:ca:d5:f1", "NetworkInterfaceId": "eni-09f8ba40f97bbc142", "OwnerId": "440730077537", "PrivateDnsName": "ip-172-31-40-37.ec2.internal", "PrivateIpAddress": "172.31.40.37", "PrivateIpAddresses": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-18-232-70-66.compute-1.amazonaws.com", "PublicIp": "18.232.70.66" }, "Primary": true, "PrivateDnsName": "ip-172-31-40-37.ec2.internal", "PrivateIpAddress": "172.31.40.37" } ], "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-17a00f48", "VpcId": "vpc-7166990c", "InterfaceType": "interface" } ], "RootDeviceName": "/dev/sda1", "RootDeviceType": "ebs", "SecurityGroups": [ { "GroupName": "launch-wizard-3", "GroupId": "sg-0976be2478d3b8b08" } ], "SourceDestCheck": true, "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 1 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "HibernationOptions": { "Configured": false }, "MetadataOptions": { "State": "applied", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled" } } ], "OwnerId": "440730077537", "ReservationId": "r-06e3113829e85cdc6" } ] } - Listar VMs (em formato tabela):
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
$ aws ec2 describe-instances --output table ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | DescribeInstances | +----------------------------------------------------------------------------------------------------------------------------------------------------------------+ || Reservations || |+------------------------------------------------------------------+-------------------------------------------------------------------------------------------+| || OwnerId | 440730077537 || || RequesterId | 940372691376 || || ReservationId | r-04e5222922400810c || |+------------------------------------------------------------------+-------------------------------------------------------------------------------------------+| ||| Instances ||| ||+-------------------------------------------------------+----------------------------------------------------------------------------------------------------+|| ||| AmiLaunchIndex | 0 ||| ||| Architecture | x86_64 ||| ||| ClientToken | cb65d27a-49cb-d46d-a7ca-1b8368d22330 ||| ||| EbsOptimized | False ||| ||| EnaSupport | True ||| ||| Hypervisor | xen ||| ||| ImageId | ami-0914bc04e5495b889 ||| ||| InstanceId | i-0eea6b50a48d07613 ||| ||| InstanceType | t2.micro ||| ||| LaunchTime | 2020-09-18T00:17:13.000Z ||| ||| PrivateDnsName | ||| ||| PublicDnsName | ||| ||| RootDeviceName | /dev/xvda ||| ||| RootDeviceType | ebs ||| ||| StateTransitionReason | User initiated (2020-09-20 20:10:17 GMT) ||| ||| VirtualizationType | hvm ||| ||+-------------------------------------------------------+----------------------------------------------------------------------------------------------------+|| |||| CapacityReservationSpecification |||| |||+----------------------------------------------------------------------------------------------------------------------------+-----------------------------+||| |||| CapacityReservationPreference | open |||| |||+----------------------------------------------------------------------------------------------------------------------------+-----------------------------+||| |||| CpuOptions |||| |||+------------------------------------------------------------------------------------------------------------------------+---------------------------------+||| |||| CoreCount | 1 |||| |||| ThreadsPerCore | 1 |||| |||+------------------------------------------------------------------------------------------------------------------------+---------------------------------+||| |||| HibernationOptions |||| |||+---------------------------------------------------------------------------------------------+------------------------------------------------------------+||| |||| Configured | False |||| |||+---------------------------------------------------------------------------------------------+------------------------------------------------------------+||| |||| MetadataOptions |||| |||+----------------------------------------------------------------------------------------------------------+-----------------------------------------------+||| |||| HttpEndpoint | enabled |||| |||| HttpPutResponseHopLimit | 1 |||| |||| HttpTokens | optional |||| |||| State | pending |||| |||+----------------------------------------------------------------------------------------------------------+-----------------------------------------------+||| |||| Monitoring |||| |||+-----------------------------------------------------------------+----------------------------------------------------------------------------------------+||| |||| State | disabled |||| |||+-----------------------------------------------------------------+----------------------------------------------------------------------------------------+||| |||| Placement |||| |||+------------------------------------------------------------------------------------------+---------------------------------------------------------------+||| |||| AvailabilityZone | us-east-1c |||| |||| GroupName | |||| |||| Tenancy | default |||| |||+------------------------------------------------------------------------------------------+---------------------------------------------------------------+||| |||| State |||| |||+-------------------------------------------------------+--------------------------------------------------------------------------------------------------+||| |||| Code | 48 |||| |||| Name | terminated |||| |||+-------------------------------------------------------+--------------------------------------------------------------------------------------------------+||| |||| StateReason |||| |||+-----------------------+----------------------------------------------------------------------------------------------------------------------------------+||| |||| Code | Client.UserInitiatedShutdown |||| |||| Message | Client.UserInitiatedShutdown: User initiated shutdown |||| |||+-----------------------+----------------------------------------------------------------------------------------------------------------------------------+||| |||| Tags |||| |||+-----------------------------------+----------------------------------------------------------------------------------------------------------------------+||| |||| Key | Value |||| |||+-----------------------------------+----------------------------------------------------------------------------------------------------------------------+||| |||| aws:cloudformation:stack-id | arn:aws:cloudformation:us-east-1:440730077537:stack/awseb-e-32fei49nnj-stack/35d81f30-f944-11ea-9cb6-0eb23bbe71c5 |||| |||| elasticbeanstalk:environment-id | e-32fei49nnj |||| |||| Name | Fiapapp-env |||| |||| aws:cloudformation:stack-name | awseb-e-32fei49nnj-stack |||| |||| elasticbeanstalk:environment-name| Fiapapp-env |||| |||| aws:autoscaling:groupName | awseb-e-32fei49nnj-stack-AWSEBAutoScalingGroup-17NY3APZ43NN7 |||| |||| aws:cloudformation:logical-id | AWSEBAutoScalingGroup |||| |||+-----------------------------------+----------------------------------------------------------------------------------------------------------------------+||| || Reservations || |+------------------------------------------------------------------+-------------------------------------------------------------------------------------------+| || OwnerId | 440730077537 || || RequesterId | || || ReservationId | r-06e3113829e85cdc6 || |+------------------------------------------------------------------+-------------------------------------------------------------------------------------------+| ||| Instances ||| ||+-------------------------------------------------------+----------------------------------------------------------------------------------------------------+|| ||| AmiLaunchIndex | 0 ||| ||| Architecture | x86_64 ||| ||| ClientToken | ||| ||| EbsOptimized | False ||| ||| EnaSupport | True ||| ||| Hypervisor | xen ||| ||| ImageId | ami-0817d428a6fb68645 ||| ||| InstanceId | i-02a7e6dfe99d1f769 ||| ||| InstanceType | t2.micro ||| ||| KeyName | fiap ||| ||| LaunchTime | 2020-09-20T20:11:49.000Z ||| ||| PrivateDnsName | ip-172-31-40-37.ec2.internal ||| ||| PrivateIpAddress | 172.31.40.37 ||| ||| PublicDnsName | ec2-18-232-70-66.compute-1.amazonaws.com ||| ||| PublicIpAddress | 18.232.70.66 ||| ||| RootDeviceName | /dev/sda1 ||| ||| RootDeviceType | ebs ||| ||| SourceDestCheck | True ||| ||| StateTransitionReason | ||| ||| SubnetId | subnet-17a00f48 ||| ||| VirtualizationType | hvm ||| ||| VpcId | vpc-7166990c ||| ||+-------------------------------------------------------+----------------------------------------------------------------------------------------------------+|| |||| BlockDeviceMappings |||| |||+-------------------------------------------------------------------------------+--------------------------------------------------------------------------+||| |||| DeviceName | /dev/sda1 |||| |||+-------------------------------------------------------------------------------+--------------------------------------------------------------------------+||| ||||| Ebs ||||| ||||+-------------------------------------------------------------------+------------------------------------------------------------------------------------+|||| ||||| AttachTime | 2020-09-20T20:11:49.000Z ||||| ||||| DeleteOnTermination | True ||||| ||||| Status | attached ||||| ||||| VolumeId | vol-0b8b82a6443e712cf ||||| ||||+-------------------------------------------------------------------+------------------------------------------------------------------------------------+|||| |||| CapacityReservationSpecification |||| |||+----------------------------------------------------------------------------------------------------------------------------+-----------------------------+||| |||| CapacityReservationPreference | open |||| |||+----------------------------------------------------------------------------------------------------------------------------+-----------------------------+||| |||| CpuOptions |||| |||+------------------------------------------------------------------------------------------------------------------------+---------------------------------+||| |||| CoreCount | 1 |||| |||| ThreadsPerCore | 1 |||| |||+------------------------------------------------------------------------------------------------------------------------+---------------------------------+||| |||| HibernationOptions |||| |||+---------------------------------------------------------------------------------------------+------------------------------------------------------------+||| |||| Configured | False |||| |||+---------------------------------------------------------------------------------------------+------------------------------------------------------------+||| |||| MetadataOptions |||| |||+----------------------------------------------------------------------------------------------------------+-----------------------------------------------+||| |||| HttpEndpoint | enabled |||| |||| HttpPutResponseHopLimit | 1 |||| |||| HttpTokens | optional |||| |||| State | applied |||| |||+----------------------------------------------------------------------------------------------------------+-----------------------------------------------+||| |||| Monitoring |||| |||+-----------------------------------------------------------------+----------------------------------------------------------------------------------------+||| |||| State | disabled |||| |||+-----------------------------------------------------------------+----------------------------------------------------------------------------------------+||| |||| NetworkInterfaces |||| |||+--------------------------------------------------------------+-------------------------------------------------------------------------------------------+||| |||| Description | |||| |||| InterfaceType | interface |||| |||| MacAddress | 0e:6a:4f:ca:d5:f1 |||| |||| NetworkInterfaceId | eni-09f8ba40f97bbc142 |||| |||| OwnerId | 440730077537 |||| |||| PrivateDnsName | ip-172-31-40-37.ec2.internal |||| |||| PrivateIpAddress | 172.31.40.37 |||| |||| SourceDestCheck | True |||| |||| Status | in-use |||| |||| SubnetId | subnet-17a00f48 |||| |||| VpcId | vpc-7166990c |||| |||+--------------------------------------------------------------+-------------------------------------------------------------------------------------------+||| ||||| Association ||||| ||||+-----------------------------------------+--------------------------------------------------------------------------------------------------------------+|||| ||||| IpOwnerId | amazon ||||| ||||| PublicDnsName | ec2-18-232-70-66.compute-1.amazonaws.com ||||| ||||| PublicIp | 18.232.70.66 ||||| ||||+-----------------------------------------+--------------------------------------------------------------------------------------------------------------+|||| ||||| Attachment ||||| ||||+--------------------------------------------------------------+-----------------------------------------------------------------------------------------+|||| ||||| AttachTime | 2020-09-20T20:11:49.000Z ||||| ||||| AttachmentId | eni-attach-00f1dc9a09492b219 ||||| ||||| DeleteOnTermination | True ||||| ||||| DeviceIndex | 0 ||||| ||||| Status | attached ||||| ||||+--------------------------------------------------------------+-----------------------------------------------------------------------------------------+|||| ||||| Groups ||||| ||||+----------------------------------------------------+---------------------------------------------------------------------------------------------------+|||| ||||| GroupId | sg-0976be2478d3b8b08 ||||| ||||| GroupName | launch-wizard-3 ||||| ||||+----------------------------------------------------+---------------------------------------------------------------------------------------------------+|||| ||||| PrivateIpAddresses ||||| ||||+---------------------------------------------------------+----------------------------------------------------------------------------------------------+|||| ||||| Primary | True ||||| ||||| PrivateDnsName | ip-172-31-40-37.ec2.internal ||||| ||||| PrivateIpAddress | 172.31.40.37 ||||| ||||+---------------------------------------------------------+----------------------------------------------------------------------------------------------+|||| |||||| Association |||||| |||||+----------------------------------------+-------------------------------------------------------------------------------------------------------------+||||| |||||| IpOwnerId | amazon |||||| |||||| PublicDnsName | ec2-18-232-70-66.compute-1.amazonaws.com |||||| |||||| PublicIp | 18.232.70.66 |||||| |||||+----------------------------------------+-------------------------------------------------------------------------------------------------------------+||||| |||| Placement |||| |||+------------------------------------------------------------------------------------------+---------------------------------------------------------------+||| |||| AvailabilityZone | us-east-1a |||| |||| GroupName | |||| |||| Tenancy | default |||| |||+------------------------------------------------------------------------------------------+---------------------------------------------------------------+||| |||| SecurityGroups |||| |||+-----------------------------------------------------+----------------------------------------------------------------------------------------------------+||| |||| GroupId | sg-0976be2478d3b8b08 |||| |||| GroupName | launch-wizard-3 |||| |||+-----------------------------------------------------+----------------------------------------------------------------------------------------------------+||| |||| State |||| |||+----------------------------------------------------------------+-----------------------------------------------------------------------------------------+||| |||| Code | 16 |||| |||| Name | running |||| |||+----------------------------------------------------------------+-----------------------------------------------------------------------------------------+|||
Criando o DB no DynamoDB
Accessando via código python
Usando o arquivo de credenciais
- Na VM, instalar o
git:1
$ sudo yum install -y git
- Clonar o repostiorio das aulas:
1
$ git clone https://github.com/josecastillolema/fiap.git
- Navegar ate a pasta dos códigos de este lab:
1
$ cd fiap/shift/multicloud/lab08-paas-dynamo/
- Conferir o código:
- Carrega a tabela
Alunosda regionus-east-1 - Faz um scan de todos os dados da tabela
- Insere um novo aluno
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
from pprint import pprint import boto3 dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('Alunos') def scan(dynamodb, table): response = table.scan() data = response['Items'] while 'LastEvaluatedKey' in response: response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey']) data.extend(response['Items']) print (data) def put_aluno(dynamodb, table, rm, mail, nome, tlfne): response = table.put_item( Item={ 'RM': rm, 'mail': mail, 'nome': nome, 'tfne': tlfne } ) return response if __name__ == '__main__': print("\nTestando scan:") scan(dynamodb, table) resp = put_aluno(dynamodb, table, "RM234472", 'rm234472@fiap.com.br', "Jonas Kahnwald", 11636229987) print("\nIserindo aluno:") pprint(resp)
- Carrega a tabela
- Instalar as dependências:
1
$ pip3 install boto3
- Rodar o código:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ python3 dynamodb.py Testando scan: [{'mail': 'rm234472@fiap.com.br', 'nome': 'Jonas Kahnwald', 'RM': 'RM234472', 'tlfne': Decimal('11636229987')}, {'mail': 'rm338132@fiap.com.br', 'nome': 'Joao Lopez', 'RM': 'RM338132', 'tfne': Decimal('11981041293')}] Iserindo aluno: {'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive', 'content-length': '2', 'content-type': 'application/x-amz-json-1.0', 'date': 'Thu, 30 Jul 2020 17:41:36 GMT', 'server': 'Server', 'x-amz-crc32': '2745614147', 'x-amzn-requestid': 'KDPGDR3S23O19GMPMPOPHCNEO3VV4KQNSO5AEMVJF66Q9ASUAAJG'}, 'HTTPStatusCode': 200, 'RequestId': 'KDPGDR3S23O19GMPMPOPHCNEO3VV4KQNSO5AEMVJF66Q9ASUAAJG', 'RetryAttempts': 0}} - No console do DynamoDB, conferir que o novo aluno foi inserido:

Usando IAM roles (recomendado)
- Remover o arquivo de credenciais:
1
$ rm -rf ~/.aws
- Tentar rodar de novo o código (deberia falhar, pois não estamos mais autenticados):
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
$ python3 dynamodb.py Testando scan: Traceback (most recent call last): File "dynamodb2.py", line 28, in <module> scan(dynamodb, table) File "dynamodb2.py", line 8, in scan response = table.scan() File "/usr/lib/python3/dist-packages/boto3/resources/factory.py", line 520, in do_action response = action(self, *args, **kwargs) File "/usr/lib/python3/dist-packages/boto3/resources/action.py", line 83, in __call__ response = getattr(parent.meta.client, operation_name)(**params) File "/usr/lib/python3/dist-packages/botocore/client.py", line 316, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/lib/python3/dist-packages/botocore/client.py", line 622, in _make_api_call operation_model, request_dict, request_context) File "/usr/lib/python3/dist-packages/botocore/client.py", line 641, in _make_request return self._endpoint.make_request(operation_model, request_dict) File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 102, in make_request return self._send_request(request_dict, operation_model) File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 132, in _send_request request = self.create_request(request_dict, operation_model) File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 116, in create_request operation_name=operation_model.name) File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 356, in emit return self._emitter.emit(aliased_event_name, **kwargs) File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 228, in emit return self._emit(event_name, kwargs) File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 211, in _emit response = handler(**kwargs) File "/usr/lib/python3/dist-packages/botocore/signers.py", line 90, in handler return self.sign(operation_name, request) File "/usr/lib/python3/dist-packages/botocore/signers.py", line 160, in sign auth.add_auth(request) File "/usr/lib/python3/dist-packages/botocore/auth.py", line 357, in add_auth raise NoCredentialsError botocore.exceptions.NoCredentialsError: Unable to locate credentials - Nas contas da AWS Academy, basta nexar o role
LabInstanceProfilena VM e rodar de novo o código (deberia funcionar):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
```
$ python3 dynamodb.py
Testando scan:
[{'mail': 'rm234472@fiap.com.br', 'nome': 'Jonas Kahnwald', 'RM': 'RM234472', 'tfne': Decimal('11636229987')}, {'mail': 'rm338132@fiap.com.br', 'nome': 'Joao Lopez', 'RM': 'RM338132', 'tfne': Decimal('11981041293')}]
Iserindo aluno:
{'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
'content-length': '2',
'content-type': 'application/x-amz-json-1.0',
'date': 'Wed, 05 Aug 2020 08:39:34 GMT',
'server': 'Server',
'x-amz-crc32': '2745614147',
'x-amzn-requestid': 'ESPGDHO1356RNOVANUH18ASV6NVV4KQNSO5AEMVJF66Q9ASUAAJG'},
'HTTPStatusCode': 200,
'RequestId': 'ESPGDHO1356RNOVANUH18ASV6NVV4KQNSO5AEMVJF66Q9ASUAAJG',
'RetryAttempts': 0}}
```
Tentar rodar de novo o código (deberia funcionar):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ python3 dynamodb.py Testando scan: [{'mail': 'rm234472@fiap.com.br', 'nome': 'Jonas Kahnwald', 'RM': 'RM234472', 'tfne': Decimal('11636229987')}, {'mail': 'rm338132@fiap.com.br', 'nome': 'Joao Lopez', 'RM': 'RM338132', 'tfne': Decimal('11981041293')}] Iserindo aluno: {'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive', 'content-length': '2', 'content-type': 'application/x-amz-json-1.0', 'date': 'Wed, 05 Aug 2020 08:39:34 GMT', 'server': 'Server', 'x-amz-crc32': '2745614147', 'x-amzn-requestid': 'ESPGDHO1356RNOVANUH18ASV6NVV4KQNSO5AEMVJF66Q9ASUAAJG'}, 'HTTPStatusCode': 200, 'RequestId': 'ESPGDHO1356RNOVANUH18ASV6NVV4KQNSO5AEMVJF66Q9ASUAAJG', 'RetryAttempts': 0}}
This post is licensed under CC BY 4.0 by the author.














