我是 AWS 开发工具包 API 的新手。
我有一个 s3 存储桶(my-bucket)用于我的客户从那里下载文件。每当我的客户端从“my-bucket”下载文件时,我有一个 Trail(my-trail)用于将日志传送到另一个 s3 存储桶(my-bucket-logs)。
我想从“my-bucket-logs”中读取日志并将它们保存在我的 CMS 中以生成各种报告。是否可以获取日志?我试过下面的PHP代码。我不确定这段代码是否正确。
require 'vendor/autoload.php';
$config = [
'version' => 'latest',
'region' => 'us-east-1',
'key' => MY_AWS_KEY,
'secret' => MY_AWS_SECRETE
];
$s3client = new Aws\S3\S3Client($config);
$trailClient = new Aws\CloudTrail\CloudTrailClient($config);
$result = $trailClient->lookupEvents([
'EndTime' => time(),
'LookupAttributes' => [
[
'AttributeKey' => 'eventName',// 'get', // REQUIRED
'AttributeValue' => 'ListObjects' //get', // REQUIRED
],
// ...
],
'MaxResults' => 1000
//'NextToken' => '<string>',
//'StartTime' => '01/12/2017',
]);
print_r($result);
收到此错误:
PHP Fatal error: Uncaught exception 'Aws\CloudTrail\Exception\CloudTrailException' with message 'Error executing "LookupEvents" on "https://cloudtrail.us-east-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://cloudtrail.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"InvalidLookupAttributesException","Message":"You cannot perform a lookup on this attribute key: EventId|Event (truncated...)
InvalidLookupAttributesException (client): You cannot perform a lookup on this attribute key: EventId|EventName|Username|ResourceType|ResourceName|EventSource - {"__type":"InvalidLookupAttributesException","Message":"You cannot perform a lookup on this attribute key: EventId|EventName|Username|ResourceType|ResourceName|EventSource"}'
exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://cloudtrail.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"InvalidLookupAttributesException","Message":"You cannot perform a lookup on this attribu in /home/shahid/webroot/shahid/aws/sdk/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191
是否可以在 PHP 中使用 AWS 开发工具包 API 获取日志?