简体   繁体   English

适用于PHP的AWS开发工具包生成CloudWatch事件(putEvents)的示例

[英]Example for AWS SDK for PHP to generate CloudWatch event (putEvents)

I'm looking to generate an event on CloudWatch by invoking the putEVents on the AWS PHP SDK 3. 我希望通过在AWS PHP SDK 3上调用putEVents在CloudWatch上生成事件。

I've checked the docu online, especially at https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/cw-examples-sending-events.html 我已经在线检查了文档,尤其是在https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/cw-examples-sending-events.html

But I keep getting an error saying "Detail is malformed". 但是我一直收到错误消息,说“详细信息格式错误”。 Any help on this? 有什么帮助吗? Ideally an example that works would help a lot. 理想情况下,一个可行的例子会很有帮助。

I'm using the following: 我正在使用以下内容:

$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());
}

Thanks a lot. 非常感谢。

Your error is caused by the Detail parameter in putEvents() . 您的错误是由putEvents()Detail参数引起的。 This parameter is a json string. 此参数是json字符串。

$detail->key = "key";
$detail->value = "4";

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM