我正在尝试设置一个 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: Unable to marshal response error 是什么意思或如何修复它。
我传递来运行 Test lambda 的有效负载应该无关紧要,因为我没有使用 commands 参数,但它是:
{
"command": "ls"
}
任何帮助,将不胜感激