Classes/Command/S3CommandController.php
/**
     * Checks the connection
     *
     * This command checks if the configured credentials and connectivity allows for connecting with the S3 web service.
     *
     * By default, this command will run the "list buckets" operation on the S3 web service. If your IAM policy does
     * not allow listing buckets, you can pass a specific bucket through the "--bucket" argument. In that case, this
     * command will try to retrieve meta data only for that given bucket using the "head bucket" operation.
     *
     * @param string|null $bucket If specified, we try to connect by retrieving meta data for this specific bucket only
     * @param string $prefix
     * @return void
     */
Checks the connection
This command checks if the configured credentials and connectivity allows for connecting with the S3 web service.

By default, this command will run the "list buckets" operation on the S3 web service. If your IAM policy does
not allow listing buckets, you can pass a specific bucket through the "--bucket" argument. In that case, this
command will try to retrieve meta data only for that given bucket using the "head bucket" operation.

@param string|null $bucket If specified, we try to connect by retrieving meta data for this specific bucket only
@param string $prefix
@return void
Checks the connection This command checks if the configured credentials and connectivity allows for connecting with the S3 web service . By default this command will run the " list buckets " operation on the S3 web service . If your IAM policy does not allow listing buckets you can pass a specific bucket through the " -- bucket " argument . In that case this command will try to retrieve meta data only for that given bucket using the " head bucket " operation . @param string|null $bucket If specified we try to connect by retrieving meta data for this specific bucket only @param string $prefix @return void
public function connectCommand(string $bucket = null, string $prefix = ''): void
    {
        try {
            if ($bucket !== null) {
                $this->s3Client->registerStreamWrapper();
                $this->outputLine('Access list of objects in bucket "%s" with key prefix "%s" ...', [$bucket, $prefix]);
                $this->s3Client->getPaginator('ListObjects', ['Bucket' => $bucket, 'Prefix' => $prefix]);
                $options = [
                    'Bucket' => $bucket,
                    'Body' => 'test',
                    'ContentLength' => 4,
                    'ContentType' => 'text/plain',
                    'Key' => $prefix . 'Flownative.Aws.S3.ConnectionTest.txt'
                ];
                $this->outputLine('Writing test object into bucket (arn:aws:s3:::%s/%s) ...', [$bucket, $options['Key']]);
                $this->s3Client->putObject($options);
                $this->outputLine('Deleting test object from bucket ...');
                $options = [
                    'Bucket' => $bucket,
                    'Key' => $prefix . 'Flownative.Aws.S3.ConnectionTest.txt'
                ];
                $this->s3Client->deleteObject($options);
            } else {
                $this->outputLine('Listing buckets ...');
                $this->s3Client->listBuckets();
            }
        } catch (\Exception $e) {
            $this->outputLine('<b>' . $e->getMessage() . '</b>');
            if ($bucket === null || $prefix === '') {
                $this->outputLine('Hint: Maybe your IAM policy restricts the user from listing all buckets. In that case, try using the "--bucket" and "--prefix" arguments.');
            }
            $this->quit(1);
        }
        $this->outputLine();
        $this->outputLine('OK');
    }
public function connectCommand ( string $ bucket = null , string $ prefix = '' ) : void { try { if ( $ bucket !== null ) { $ this -> s3Client -> registerStreamWrapper ( ) ; $ this -> outputLine ( 'Access list of objects in bucket "%s" with key prefix "%s" ...' , [ $ bucket , $ prefix ] ) ; $ this -> s3Client -> getPaginator ( 'ListObjects' , [ 'Bucket' => $ bucket , 'Prefix' => $ prefix ] ) ; $ options = [ 'Bucket' => $ bucket , 'Body' => 'test' , 'ContentLength' => 4 , 'ContentType' => 'text/plain' , 'Key' => $ prefix . 'Flownative.Aws.S3.ConnectionTest.txt' ] ; $ this -> outputLine ( 'Writing test object into bucket (arn:aws:s3:::%s/%s) ...' , [ $ bucket , $ options [ 'Key' ] ] ) ; $ this -> s3Client -> putObject ( $ options ) ; $ this -> outputLine ( 'Deleting test object from bucket ...' ) ; $ options = [ 'Bucket' => $ bucket , 'Key' => $ prefix . 'Flownative.Aws.S3.ConnectionTest.txt' ] ; $ this -> s3Client -> deleteObject ( $ options ) ; } else { $ this -> outputLine ( 'Listing buckets ...' ) ; $ this -> s3Client -> listBuckets ( ) ; } } catch ( \ Exception $ e ) { $ this -> outputLine ( '<b>' . $ e -> getMessage ( ) . '</b>' ) ; if ( $ bucket === null || $ prefix === '' ) { $ this -> outputLine ( 'Hint: Maybe your IAM policy restricts the user from listing all buckets. In that case, try using the "--bucket" and "--prefix" arguments.' ) ; } $ this -> quit ( 1 ) ; } $ this -> outputLine ( ) ; $ this -> outputLine ( 'OK' ) ; }
Checks the connection
 This command checks if the configured credentials and connectivity allows for connecting with the S3 web service.
Checks the connection This command checks if the configured credentials and connectivity allows for connecting with the S3 web service .