I am trying to execute aws s3 cp command in Powershell. I have a list of files which I defined in an array-like below.
$filearray = ("file1.txt", "file2.txt", "file3.txt", "file4.txt", "file5.txt")
Now when I am trying to copy these files from s3 using aws s3 cp command nothing works.
$filearray | foreach { "aws s3 cp s3://<bucket_name/path_to_file/$_ . --sse aws:kms --sse-kms-key-id 12345-abcxzd" }
I tried below as well. But it didn't work. Can someone point out the mistake I am doing?
foreach ($element in $filearray) { "aws s3 cp s3://<bucket_name/path_to_file/$element . --sse aws:kms --sse-kms-key-id 12345-abcxzd" }
Now I have added variables to my aws command also which will be like below when the loop executes.
$kms_key_option="--sse aws:kms --sse-kms-key-id 12345-abcxzd"
$s3_location="s3://<bucket_name/path_to_file/"
foreach ($element in $filearray) { & aws s3 cp $s3_location/$element $current_location $kms_key_option }
But there is a catch in this. Only the first 2 variables in command block work as variables rest 2 do not work as variables. i.e. $current_location $kms_key_option So the problem statement is changing here a little bit.
Note: I have aws cli installed on my windows machine it works with normal command but it doesn't work in foreach loop.