Install the AWS Tools for PowerShell. You can easily install it by using the following:
Install-Module -Name AWSPowerShell
AWS Credentials: Make sure you have configured your AWS credentials. You can configure them using
Set-AWSCredential -AccessKey <YourAccessKey> -SecretKey <YourSecretKey> -StoreAs <ProfileName>
Or use the default credentials file located at ~/.aws/credentials.
Upload a File to S3:
Specify the Bucket Name and File Path:
BucketName: The name of your S3 bucket to which the file is intended for upload.
FilePath: Local path of the file on your machine you want to upload.
Key: The key (or name) under which the file will be stored in the bucket.
Upload the file using Write-S3Object cmdlet:
$bucketName = "your-s3-bucket-name"
$filePath = "C:\path\to\your\file.txt"
$key = "foldername/filename.txt"
Write-S3Object -BucketName $bucketName -File $filePath -Key $key
Suppose that you created a document.txt file in the directory C:\Users\YourUser\Documents\, which you would like to upload to an S3 bucket named mybucket, storing it under the key docs/document.txt.
$bucketName = "mybucket"
$filePath = "C:\Users\YourUser\Documents\document.txt"
$key = "docs/document.txt"
Write-S3Object -BucketName $bucketName -File $filePath -Key $key
The command will upload the file to your specified S3 bucket under the given key.
If you face permission issues, make sure your IAM user has
s3: PutObject permission set for the given bucket.
Comments