Skip to content

Commit 24233cb

Browse files
committed
Adds the ExpressRunner.php file and fixes some missing data cleanup.
1 parent a7f98a0 commit 24233cb

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
namespace S3;
6+
7+
use Aws\Exception\AwsException;
8+
use AwsUtilities\RunnableExample;
9+
10+
require_once __DIR__ . "/vendor/autoload.php";
11+
12+
require "S3ExpressBasics.php";
13+
14+
try {
15+
/**
16+
* @var RunnableExample $runner
17+
*/
18+
$runner = new S3ExpressBasics();
19+
$runner->helloService();
20+
$runner->runExample();
21+
} catch (AwsException $error) {
22+
echo "Errored with the following: (" . $error->getCode() . ") - " . $error->getMessage();
23+
} finally {
24+
echo "Cleaning up.\n";
25+
$runner->cleanUp();
26+
}

php/example_code/s3/S3ExpressBasics.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* or as a PHPUnit test:
2020
* vendor/bin/phpunit S3ExpressBasicsTests.php
21-
* /**/
21+
**/
2222

2323
namespace S3;
2424
use Aws\CloudFormation\CloudFormationClient;
@@ -123,7 +123,7 @@ public function runExample()
123123
echo "Error waiting for the CloudFormation stack to create: {$caught->getAwsErrorMessage()}\n";
124124
throw $caught;
125125
}
126-
$this->resources['StackName'] = $stackName;
126+
$this->resources['stackName'] = $stackName;
127127
$stackInfo = $this->cloudFormationClient->describeStacks([
128128
'StackName' => $result['StackId'],
129129
]);
@@ -138,10 +138,14 @@ public function runExample()
138138
$expressUserName = $output['OutputValue'];
139139
}
140140
}
141+
$this->resources['regularUserName'] = $regularUserName;
142+
$this->resources['expressUserName'] = $expressUserName;
141143
$regularKey = $this->iamService->createAccessKey($regularUserName);
142144
$regularCredentials = new Credentials($regularKey['AccessKeyId'], $regularKey['SecretAccessKey']);
145+
$this->resources['regularKey'] = $regularKey['AccessKeyId'];
143146
$expressKey = $this->iamService->createAccessKey($expressUserName);
144147
$expressCredentials = new Credentials($expressKey['AccessKeyId'], $expressKey['SecretAccessKey']);
148+
$this->resources['expressKey'] = $expressKey['AccessKeyId'];
145149

146150
// 3. Create an additional client using the credentials with S3 Express permissions.
147151
echo "\n";
@@ -317,19 +321,30 @@ public function cleanUp()
317321
}
318322

319323
//delete the stack
320-
if(isset($this->resources['StackName'])){
324+
if(isset($this->resources['stackName'])){
321325
$this->cloudFormationClient->deleteStack([
322-
'StackName' => $this->resources['StackName'],
326+
'StackName' => $this->resources['stackName'],
323327
]);
324-
unset($this->resources['StackName']);
328+
unset($this->resources['stackName']);
325329
}
326330

327-
// $this->iamService->deleteRole($this->resources['roleName']);
328-
// unset($this->resources['roleName']);
329-
330-
// delete User
331-
// $this->iamService->deleteUser($this->resources['userName']);
332-
// unset($this->resources['userName']);
331+
// delete User data
332+
if(isset($this->resources['regularKey'])) {
333+
$this->iamService->deleteAccessKey($this->resources['regularKey'], $this->resources['regularUserName']);
334+
unset($this->resources['regularKey']);
335+
}
336+
if(isset($this->resources['regularUserName'])) {
337+
$this->iamService->deleteUser($this->resources['regularUserName']);
338+
unset($this->resources['regularUserName']);
339+
}
340+
if(isset($this->resources['expressKey'])) {
341+
$this->iamService->deleteAccessKey($this->resources['expressKey'], $this->resources['expressUserName']);
342+
unset($this->resources['expressKey']);
343+
}
344+
if(isset($this->resources['expressUserName'])) {
345+
$this->iamService->deleteUser($this->resources['expressUserName']);
346+
unset($this->resources['expressUserName']);
347+
}
333348

334349
// delete all the objects in both buckets
335350
if(isset($this->resources['objectKey'])){

0 commit comments

Comments
 (0)