我正在尝试设置一个AWS lambda,它将在我的EC2实例中启动SSM会话并运行命令。为了简单起见,我现在正尝试运行ls。这是我的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
但是,当我在此函数上运行“测试”时,得到以下日志输出:
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
我不确定此Runtime.MarshalError:无法编组响应错误的含义或解决方法。
我传递给运行测试lambda的有效负载无关紧要,因为我没有使用commands参数,而是:
{
"command": "ls"
}
任何帮助,将不胜感激
该错误的措辞非常清楚,您只是在错误的部分进行操作。
我假设您在resp
对象的某处使用对象,并且该部分尝试执行类似json.load()
或相关的操作。
datetime.datetime(2020, 5, 12, 19, 34, 36, 349000, tzinfo=tzlocal()) is not JSON serializable
datetime
对于第一次碰到的人来说,这是一个常见错误,这是一个非常全面的问题:如何克服“ datetime.datetime不能序列化JSON”?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句