简体   繁体   English

当我尝试更新 dynamodb 时出现内部服务器错误

[英]Internal Server Error when i try to update dynamodb

I have a problem updating data in dynamodb, when I send a request to my route to update patients it returns status 500 but I couldn't find out what is causing this error, I'm using express with serverless and api gateway我在 dynamodb 中更新数据时遇到问题,当我向我的路由发送更新患者的请求时,它返回状态 500 但我无法找出导致此错误的原因,我正在使用 express with serverless 和 api 网关

my controller我的 controller

 import { Response, Request } from 'express'; import { updatePatientsService } from '../../services/patients/updatePatientsService'; import { getPatientsByIdSerive } from '../../services/patients/getPatientsByIdService'; const updatePatientsController = async (res: Response, req: Request) => { const { id } = req.params; const { Item: patient } = await getPatientsByIdSerive(id); if (.patient) return res.status(404);send('patient not found'). const newPatientUpdate = await updatePatientsService(req;body). return res.status(200);json(newPatientUpdate); }; export { updatePatientsController };

my service我的服务

 import AWS from 'aws-sdk'; import { Patient } from '../../types/interfaces/Patient'; const dynamoClient = new AWS.DynamoDB.DocumentClient(); const tableName = process.env.PATIENTS_TABLE; const updatePatientsService = async (patient: Patient) => { const params = { TableName: tableName,: Item. {..,patient, }; }. return await dynamoClient.put(params);promise(); }; export { updatePatientsService };

my routes我的路线

 import { Router } from 'express'; import { celebrate } from 'celebrate'; import { createPatientController } from '../../controllers/patients/createPatientController'; import { patientValidator } from '../../middlewares/validator'; import { getPatientsController } from '../../controllers/patients/getPatientsController'; import { getPatientsByIdController } from '../../controllers/patients/getPatientsByIdController'; import { updatePatientsController } from '../../controllers/patients/updatePatientsController'; const routes = Router(); routes.post('/', celebrate(patientValidator), createPatientController); routes.get('/', getPatientsController); routes.get('/:id', getPatientsByIdController); routes.put('/:id', updatePatientsController); export default routes;

A 500 exception from DynamoDB is an Internal Server Error in which something happened on the DynamoDB side which is outside of your control.来自 DynamoDB 的 500 异常是内部服务器错误,其中 DynamoDB 端发生了您无法控制的事情。 All of the AWS SDKs have built on retries which should retry the Update to completion.所有 AWS SDK 都建立在重试之上,重试应该重试更新完成。

It's important to understand that the 500 exception is being thrown by DynamoDB or another component of the stack.重要的是要了解 500 异常是由 DynamoDB 或堆栈的另一个组件抛出的。 As a 500 from elsewhere could be a different issue which is inside of your control.作为来自其他地方的 500 可能是一个不同的问题,它在您的控制范围内。

500s from DynamoDB are typically short lived and should not occur very often..来自 DynamoDB 的 500s 通常是短暂的,不应该经常发生。

I would also suggest putting try/catch blocks on Amy API request you make to ensure you don't return exceptions downstream.我还建议将 try/catch 块放在您提出的 Amy API 请求上,以确保您不会在下游返回异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试在本地 DynamoDB 上启用“生存时间”时出现 UnrecognizedClientException 错误 - UnrecognizedClientException error when I try to enable "time to live" on local DynamoDB 消息:尝试访问 AWS 网关 api 时出现“内部服务器错误” - message: "Internal server error" when try to access aws gateway api DynamoDB 更新操作中的 ConditionExpression 给出未知错误 - ConditionExpression in DynamoDB update operation gives unknown error 我在尝试注册用户时遇到错误 - I'm getting a error when I try to Sign up user 当我尝试实施该项目时,它失败了,并且出现此错误 - When I try to implement the project it fails and I get this error 为什么在使用 dynamodb 和 s3 存储桶创建 lambda 函数时出现 IamRoleLambdaExecution 错误? - Why I am getting IamRoleLambdaExecution error when creating a lambda function with dynamodb and s3 bucket? DynamoDB 更新多个值 - DynamoDB Update Multiple values DynamoDB 批量更新 - DynamoDB Batch Update 为什么在通过 API 网关调用时,Java 中的 AWS Lambda 代码返回“内部服务器错误”? - why does this AWS Lambda code in Java return "internal server error" when invoked via an API gateway? 尝试运行 docker-compose up -d 时出现错误 - I got error when try to run docker-compose up -d
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM