【问题标题】:Example for AWS SDK for PHP to generate CloudWatch event (putEvents)适用于 PHP 的 AWS 开发工具包生成 CloudWatch 事件 (putEvents) 的示例
【发布时间】:2018-10-03 09:34:39
【问题描述】:

我希望通过调用 AWS PHP SDK 3 上的 putEVents 在 CloudWatch 上生成一个事件。

我在网上查过文档,尤其是https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/cw-examples-sending-events.html

但我不断收到一条错误消息,提示“详细信息格式错误”。对此有什么帮助吗?理想情况下,一个有效的例子会有很大帮助。

我正在使用以下内容:

$client = new CloudWatchEventsClient([
    'region' => 'us-west-2',
   'version' => 'latest'
]);

try {
$result = $client->putEvents([
    'Entries' => [ // REQUIRED
        [
            'Detail' => '4',
            'DetailType' => 'sec',
            'Resources' => ['ec2'],
            'Source' => 'LocalApp'
        ],
    ],
]);
var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}

非常感谢。

【问题讨论】:

    标签: php aws-sdk amazon-cloudwatch


    【解决方案1】:

    您的错误是由putEvents() 中的Detail 参数引起的。这个参数是一个json字符串。

    $detail->key = "key";
    $detail->value = "4";
    
    $result = $client->putEvents([
        'Entries' => [ // REQUIRED
            [
                'Detail' => json_encode($detail),
                'DetailType' => 'sec',
                'Resources' => ['ec2'],
                'Source' => 'LocalApp'
            ],
        ],
    ]);
    

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 2018-09-07
      • 2013-07-19
      • 2021-07-27
      • 2015-05-29
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多