forked from awsdocs/aws-doc-sdk-examples
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetAccessKeyLastUsed.php
More file actions
48 lines (40 loc) · 1.34 KB
/
GetAccessKeyLastUsed.php
File metadata and controls
48 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
* ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/iam-examples-managing-access-keys.html
*
*
*
*/
// snippet-start:[iam.php.get_access_key_last_used.complete]
// snippet-start:[iam.php.get_access_key_last_used.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\Iam\IamClient;
// snippet-end:[iam.php.get_access_key_last_used.import]
/**
* Retrieves information about when the specified access key was last used.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
//Create an IAM Client
// snippet-start:[iam.php.get_access_key_last_used.main]
$client = new IamClient([
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2010-05-08'
]);
try {
$result = $client->getAccessKeyLastUsed([
'AccessKeyId' => 'ACCESS_KEY_ID', // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
// snippet-end:[iam.php.get_access_key_last_used.main]
// snippet-end:[iam.php.get_access_key_last_used.complete]