使用 python for put_item in dynamodb table with Lambda function
Using python for put_item in dynamodb table with Lambda function
正在编写我的第一个 Lambda 函数以使用 Python
放置项目
我遇到的问题 - 无法从注册表单(前端托管在 S3 存储桶上并启用静态 Web 主机)获取输入到 DynamoDB table
数据将通过此功能发送到托管在 AWS
上的 API
const BASE_URL = `API-URL`;
function handleForm() {
const name = document.querySelector('#name').value;
const email = document.querySelector('#email').value;
const phone = document.querySelector('#phone').value;
const data = {
name,
email,
phone
}
console.log(data);
saveDataToAWS(data);
}
async function saveDataToAWS(data) {
const result = await axios.post(BASE_URL, data);
return result.data;
}
我不确定我是否以正确的方式使用 AXIOS,但让我们继续
我现在使用的 Lambda 函数几乎是这样的:
import json
import boto3
dynamodb=boto3.resource('dynamodb')
table=dynamodb.Table('register')
def lambda_handler(event, context):
table.put_item(
Item={
'name'=event['name'],
'email'=event['email'],
'phone'=event['phone']
}
)
respone={
'mes':'Good input !'
}
return {
'statusCode': 200,
'body': respone
}
我几乎 99% 都是在 AWS 中编写代码的新手,所以我确定我做错了大部分
真的需要你的帮助!
'event' 属性有一个 'body' 参数,它将包含您示例中的数据:
data = json.loads(event["body"])
table.put_item(
Item={
'name':data['name'],
'email':data['email'],
'phone':data['phone']
}
)
记得还要检查 CloudWatch Logs,因为它会告诉您是否首先调用了 Lambda,以及是否失败。
有关 event
属性结构的更多信息,请参见此处:
https://aws-lambda-for-python-developers.readthedocs.io/en/latest/02_event_and_context/
正在编写我的第一个 Lambda 函数以使用 Python
放置项目我遇到的问题 - 无法从注册表单(前端托管在 S3 存储桶上并启用静态 Web 主机)获取输入到 DynamoDB table
数据将通过此功能发送到托管在 AWS
上的 APIconst BASE_URL = `API-URL`;
function handleForm() {
const name = document.querySelector('#name').value;
const email = document.querySelector('#email').value;
const phone = document.querySelector('#phone').value;
const data = {
name,
email,
phone
}
console.log(data);
saveDataToAWS(data);
}
async function saveDataToAWS(data) {
const result = await axios.post(BASE_URL, data);
return result.data;
}
我不确定我是否以正确的方式使用 AXIOS,但让我们继续
我现在使用的 Lambda 函数几乎是这样的:
import json
import boto3
dynamodb=boto3.resource('dynamodb')
table=dynamodb.Table('register')
def lambda_handler(event, context):
table.put_item(
Item={
'name'=event['name'],
'email'=event['email'],
'phone'=event['phone']
}
)
respone={
'mes':'Good input !'
}
return {
'statusCode': 200,
'body': respone
}
我几乎 99% 都是在 AWS 中编写代码的新手,所以我确定我做错了大部分 真的需要你的帮助!
'event' 属性有一个 'body' 参数,它将包含您示例中的数据:
data = json.loads(event["body"])
table.put_item(
Item={
'name':data['name'],
'email':data['email'],
'phone':data['phone']
}
)
记得还要检查 CloudWatch Logs,因为它会告诉您是否首先调用了 Lambda,以及是否失败。
有关 event
属性结构的更多信息,请参见此处:
https://aws-lambda-for-python-developers.readthedocs.io/en/latest/02_event_and_context/