Skip to content

Commit

Permalink
Correct bugs and paths
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-1618 committed May 25, 2023
1 parent 84f59b0 commit c9f9931
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
31 changes: 18 additions & 13 deletions lambda_functions/insert_in_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ def lambda_handler(event, context):

# Obtém o corpo da requisição
print(event)
body = json.loads(event['body'])
print(body)
try:
body = json.loads(event['body'])
print(body)

response = client.list_tables()
table_name = response['TableNames'][0]
response = client.list_tables()
table_name = response['TableNames'][0]

table = dynamodb.Table(table_name)
table = dynamodb.Table(table_name)

status = ''
# Insere o novo item na tabela
response = table.put_item(
Item={
'id': body['id'],
'name': body['name']
}
)
status = 'Item inserido com sucesso'
except:
status = 'Error. Expected json content: {"id":"<number>","name":"<name>"}'

# Insere o novo item na tabela
response = table.put_item(
Item={
'id': body['id'],
'name': body['name']
}
)

# Retorna a resposta da operação
return {
Expand All @@ -37,6 +42,6 @@ def lambda_handler(event, context):
"Access-Control-Allow-Origin" : "*",
"X-Requested-With" : "*"
},
'body': json.dumps('Item inserido com sucesso')
'body': json.dumps(status)
}

2 changes: 0 additions & 2 deletions lambda_functions/jokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import urllib3

def lambda_handler(event, context):


http = urllib3.PoolManager()
r = http.request('GET', "https://official-joke-api.appspot.com/random_joke")

Expand Down
4 changes: 0 additions & 4 deletions lambda_functions/read_dynamo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import boto3
import json





# Função Lambda que retorna todos os itens da tabela
def lambda_handler(event, context):
client = boto3.client('dynamodb')
Expand Down
19 changes: 9 additions & 10 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ function App() {
setInputValue(event.target.value);
}


async function doPostRequest() {
let payload = { 'id':Math.floor(Math.random() * 10000).toString(), name: inputValue, occupation: 'gardener' };
let res = await axios.post('https://40bc3edjdd.execute-api.us-east-1.amazonaws.com/prod/execution', payload);
let payload = { 'id':Math.floor(Math.random() * 10000).toString(), name: inputValue};
let res = await axios.post('<insert_in_dynamo_url>/execution', payload);
let data = res.data;
console.log(data);
setResponse(data);
};

async function doGetRequest() {
let payload = {};
let res = await axios.post('https://tm6tofxgqc.execute-api.us-east-1.amazonaws.com/prod/execution', payload);
let data = res.data;
console.log(data);
setValues(data);
};
async function doGetRequest() {
let payload = {};
let res = await axios.post('<read_dynamo_url>/execution', payload);
let data = res.data;
console.log(data);
setValues(data);
};


return (
Expand Down

0 comments on commit c9f9931

Please sign in to comment.