Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

999
Views
Error de AWS Lambda "No se puede ordenar la respuesta"

Estoy intentando configurar un AWS lambda que iniciará una sesión de SSM en mi instancia de EC2 y ejecutará un comando. Para simplificar, en este momento solo estoy tratando de ejecutar ls . Aquí está mi función lambda:

 import json import boto3 def lambda_handler(commands, context): """Runs commands on remote linux instances :param client: a boto/boto3 ssm client :param commands: string, each one a command to execute on the instance :return: the response from the send_command function (check the boto3 docs for ssm client.send_command() ) """ client = boto3.client('ssm') print ("Hello world") resp = client.send_command( DocumentName="AWS-RunShellScript", # Would normally pass commands param here but hardcoding it instead for testing Parameters={"commands":["ls"]}, InstanceIds=["i-01112223333"], ) return resp

Sin embargo, cuando ejecuto "Prueba" en esta función, obtengo el siguiente resultado de registro:

 START RequestId: d028de04-4004-4a0p-c8d2-975755c84777 Version: $LATEST Hello world [ERROR] Runtime.MarshalError: Unable to marshal response: datetime.datetime(2020, 5, 12, 19, 34, 36, 349000, tzinfo=tzlocal()) is not JSON serializable END RequestId: d028de04-4asdd4-4a0f-b8d2-9asd847813 REPORT RequestId: d42asd04-44d4-4a0f-b9d2-275755c6557 Duration: 1447.76 ms Billed Duration: 1500 ms Memory Size: 128 MB Max Memory Used: 76 MB Init Duration: 301.68 ms

No estoy seguro de qué significa Runtime.MarshalError: Unable to marshal response error o cómo solucionarlo.

La carga útil que estoy pasando para ejecutar Test lambda no debería importar ya que no estoy usando el parámetro de comandos, pero es:

 { "command": "ls" }

Cualquier ayuda sería apreciada

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba lo siguiente:

 return json.loads(json.dumps(resp, default=str))

Esto volcará resp como JSON y usará la función str para la serialización de fecha y hora. Luego restaura el mismo objeto, pero en lugar del objeto de fecha y hora, obtendrá cadenas que se pueden serializar.

over 4 years ago · Santiago Trujillo Report

0

El error tiene una redacción bastante clara, solo te estás fijando en la parte incorrecta.

Supongo que usa el objeto resp en algún lugar de la línea y esa parte intenta hacer algo como json.load() o algo relacionado.

 datetime.datetime(2020, 5, 12, 19, 34, 36, 349000, tzinfo=tzlocal()) is not JSON serializable

Este es un error común para las personas que se encuentran con datetime por primera vez, aquí hay una pregunta bastante completa al respecto: ¿Cómo superar "datetime.datetime not JSON serializable"?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!