我尝试了所有的方法,没有从cloudwatch中找到错误,但是数据从未到达我的rest中。
我试图从dynamodb -> lambda ->类型识别服务器创建触发器
使代码低沉
export const handler = async (event) => {
const url ="https://search.ecogroovi.com/collections/test/documents"
const apiKey = "xxxx"
const user =[]
event.Records.forEach( async (record)=> {
if (record.eventName=="INSERT"){
const data = unmarshall(record.dynamodb.NewImage)
const name =data.name
const email =data.email
const id =data.id
const headers ={
"Content-Type":"application/json",
"X-TYPESENSE-API-KEY":apiKey
}
const dataToSend ={name,email,id}
console.log(dataToSend)
axios.post(url,dataToSend,{headers}).then(response=>{
console.log(response)
return {body:JSON.stringify(response)}
})
} else {
return {message:"not insert"}
}
});
};没有数据从lambda到我的rest,也没有错误,而且有趣的事情,通常类型会发送响应,我也没有得到响应。
Im使用带有dynamodb触发器的“放大添加函数”创建lambda
请帮助任何人,7小时仅仅为了创造一些东西应该是简单的。
发布于 2022-09-04 02:50:04
感谢上面评论的好人,我把代码改成了这个.
event.Records.forEach( async (record)=> {
if (record.eventName=="INSERT"){
const data = unmarshall(record.dynamodb.NewImage)
const name =data.name
const email =data.email
const id =data.id
const headers ={
"Content-Type":"application/json",
"X-TYPESENSE-API-KEY":apiKey
}
const dataToSend ={
name:name,email:email,id:id}
console.log(dataToSend)
user.push( axios.post(url,dataToSend,{headers}));
}
});
if (user.length==0){
return Promise.resolve("no data")
}
return Promise.allSettled(user)它现在起作用了,尽管反应是错误的,但数据却是低谷的。
https://stackoverflow.com/questions/73594583
复制相似问题