There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon S3 examples using Tools for PowerShell V5
The following code examples show you how to perform actions and implement common scenarios by using the AWS Tools for PowerShell V5 with Amazon S3.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use Copy-S3Object.
- Tools for PowerShell V5
-
Example 1: This command copies the object "sample.txt" from bucket "test-files" to the same bucket but with a new key of "sample-copy.txt".
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key sample.txt -DestinationKey sample-copy.txtExample 2: This command copies the object "sample.txt" from bucket "test-files" to the bucket "backup-files" with a key of "sample-copy.txt".
Copy-S3Object -BucketName amzn-s3-demo-source-bucket -Key sample.txt -DestinationKey sample-copy.txt -DestinationBucket amzn-s3-demo-destination-bucketExample 3: This command downloads the object "sample.txt" from bucket "test-files" to a local file with name "local-sample.txt".
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key sample.txt -LocalFile local-sample.txtExample 4: Downloads the single object to the specified file. The downloaded file will be found at c:\downloads\data\archive.zip
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key data/archive.zip -LocalFolder c:\downloadsExample 5: Downloads all objects that match the specified key prefix to the local folder. The relative key hierarchy will be preserved as subfolders in the overall download location.
Copy-S3Object -BucketName amzn-s3-demo-bucket -KeyPrefix data -LocalFolder c:\downloadsExample 6: Downloads a single object to a local file using multipart parallel download for improved performance on large files.
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key sample.txt -LocalFile local-sample.txt -UseMultipartDownloadExample 7: Downloads a large object using RANGE mode with a custom 64MB part size. RANGE mode uses HTTP byte-range requests and works for all objects regardless of how they were uploaded.
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key large-file.zip -LocalFile local-large-file.zip -UseMultipartDownload -MultipartDownloadType RANGE -PartSize 64MBExample 8: Downloads all objects matching the key prefix to a local folder using multipart download with concurrent file downloads.
Copy-S3Object -BucketName amzn-s3-demo-bucket -KeyPrefix data/ -LocalFolder C:\local-data -UseMultipartDownload -DownloadFilesConcurrentlyExample 9: Downloads a single object using multipart download with 20 concurrent connections for maximum throughput on high-bandwidth networks.
Copy-S3Object -BucketName amzn-s3-demo-bucket -Key large-file.zip -LocalFile local-large-file.zip -UseMultipartDownload -ConcurrentServiceRequest 20Example 10: Downloads all objects matching the key prefix to a local folder using multipart download, continuing past individual file failures instead of aborting.
Copy-S3Object -BucketName amzn-s3-demo-bucket -KeyPrefix data/ -LocalFolder C:\local-data -UseMultipartDownload -FailurePolicy ContinueOnFailure-
For API details, see CopyObject in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Dismount-S3PSDrive.
- Tools for PowerShell V5
-
Example 1: Changes to a location outside the S3 drive, then removes the drive.
Set-Location $HOME Dismount-S3PSDrive -Name S3-
For API details, see Dismount-S3PSDrive in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3Bucket.
- Tools for PowerShell V5
-
Example 1: This command returns all S3 buckets.
Get-S3BucketExample 2: This command returns bucket named "test-files"
Get-S3Bucket -BucketName amzn-s3-demo-bucket-
For API details, see ListBuckets in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketACL.
- Tools for PowerShell V5
-
Example 1: The command gets the details of the object owner of the S3 object.
(Get-S3BucketACL -BucketName 'amzn-s3-demo-bucket' -Select *).OwnerOutput:
DisplayName Id ----------- -- testusername 9988776a6554433d22f1100112e334acb45566778899009e9887bd7f66c5f544-
For API details, see GetBucketAcl in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketAccelerateConfiguration.
- Tools for PowerShell V5
-
Example 1: This command returns the value Enabled, if the transfer acceleration settings is enabled for the bucket specified.
Get-S3BucketAccelerateConfiguration -BucketName 'amzn-s3-demo-bucket'Output:
Value ----- Enabled-
For API details, see GetBucketAccelerateConfiguration in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketAnalyticsConfiguration.
- Tools for PowerShell V5
-
Example 1: This command returns the details of the analytics filter with the name 'testfilter' in the given S3 bucket.
Get-S3BucketAnalyticsConfiguration -BucketName 'amzn-s3-demo-bucket' -AnalyticsId 'testfilter'-
For API details, see GetBucketAnalyticsConfiguration in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketAnalyticsConfigurationList.
- Tools for PowerShell V5
-
Example 1: This command returns the first 100 analytics configurations of the given S3 bucket.
Get-S3BucketAnalyticsConfigurationList -BucketName 'amzn-s3-demo-bucket'-
For API details, see ListBucketAnalyticsConfigurations in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketEncryption.
- Tools for PowerShell V5
-
Example 1: This command returns all the server side encryption rules associated with the given bucket.
Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'-
For API details, see GetBucketEncryption in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketInventoryConfiguration.
- Tools for PowerShell V5
-
Example 1: This command returns the details of the inventory named 'testinventory' for the given S3 bucket.
Get-S3BucketInventoryConfiguration -BucketName 'amzn-s3-demo-bucket' -InventoryId 'testinventory'-
For API details, see GetBucketInventoryConfiguration in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketInventoryConfigurationList.
- Tools for PowerShell V5
-
Example 1: This command returns the first 100 inventory configurations of the given S3 bucket.
Get-S3BucketInventoryConfigurationList -BucketName 'amzn-s3-demo-bucket'-
For API details, see ListBucketInventoryConfigurations in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketLocation.
- Tools for PowerShell V5
-
Example 1: This command returns the location constraint for the bucket 'amzn-s3-demo-bucket', if a constraint exists.
Get-S3BucketLocation -BucketName 'amzn-s3-demo-bucket'Output:
Value ----- ap-south-1-
For API details, see GetBucketLocation in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketLogging.
- Tools for PowerShell V5
-
Example 1: This command returns the logging status for the specified bucket.
Get-S3BucketLogging -BucketName 'amzn-s3-demo-bucket'Output:
TargetBucketName Grants TargetPrefix ---------------- ------ ------------ testbucket1 {} testprefix-
For API details, see GetBucketLogging in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketMetricsConfiguration.
- Tools for PowerShell V5
-
Example 1: This command returns the details about the metrics filter named 'testfilter' for the given S3 bucket.
Get-S3BucketMetricsConfiguration -BucketName 'amzn-s3-demo-bucket' -MetricsId 'testfilter'-
For API details, see GetBucketMetricsConfiguration in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketNotification.
- Tools for PowerShell V5
-
Example 1: This example retrieves notification configuration of the given bucket
Get-S3BucketNotification -BucketName amzn-s3-demo-bucket | select -ExpandProperty TopicConfigurationsOutput:
Id Topic -- ----- mimo arn:aws:sns:eu-west-1:123456789012:topic-1-
For API details, see GetBucketNotification in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketPolicy.
- Tools for PowerShell V5
-
Example 1: This command outputs the bucket policy associated with the given S3 bucket.
Get-S3BucketPolicy -BucketName 'amzn-s3-demo-bucket'-
For API details, see GetBucketPolicy in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketPolicyStatus.
- Tools for PowerShell V5
-
Example 1: This command returns policy status for the given S3 bucket, indicating whether the bucket is public.
Get-S3BucketPolicyStatus -BucketName 'amzn-s3-demo-bucket'-
For API details, see GetBucketPolicyStatus in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketReplication.
- Tools for PowerShell V5
-
Example 1: Returns the replication configuration information set on the bucket named 'amzn-s3-demo-bucket'.
Get-S3BucketReplication -BucketName amzn-s3-demo-bucket-
For API details, see GetBucketReplication in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketRequestPayment.
- Tools for PowerShell V5
-
Example 1: Returns the request payment configuration for the bucket named 'amzn-s3-demo-bucket'. By default, the bucket owner pays for downloads from the bucket.
Get-S3BucketRequestPayment -BucketName amzn-s3-demo-bucket-
For API details, see GetBucketRequestPayment in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use Get-S3BucketTagging.
- Tools for PowerShell V5
-
Example 1: This command returns all the tags associated with the given bucket.
Get-S3BucketTagging -BucketName 'amzn-s3-demo-bucket'-
For API details, see GetBucketTagging in AWS Tools for PowerShell Cmdlet Reference (V5).
-
The following code example shows how to use