aws-powershell

How to encrypt data using KMS key in AWS Powershell script

孤者浪人 提交于 2020-01-02 06:57:30
问题 I am trying to encrypt a text using AWS KMS and creating a powershell script. So I used New-KMSDataKey to encrypt my KMS master key which in output returns plaintextDataKey and ciphertextblob . Now I am using plaintextDataKey to encrypt my plaintext using Invoke-KMSEncrypt but I get Invalid Operation error as shown below: Below is my script: param([string]$zonesecret, [string]$KMSKey, [string]$Keyspec, [string]$region= 'us-east-1', [string]$AccessKey, [string]$SecretKey) # splat $splat = @

How can I filter AWS Instances by IAM role in powershell and get the private ip address of that instance?

大兔子大兔子 提交于 2019-12-13 18:40:43
问题 I am looking to get a script working that can filter AWS instances according to the IAM role assigned to it and then get the private ip address of it. I had asked a similar question recently: filtering ec2 instances by associated IAM role with boto where the answer has worked wonderfully. Now, I would like to do the same thing except on Windows PowerShell. I understand that PowerShell does not provide nice features as boto does however I know that there is a AWS Tools Kit for PowerShell which

AWS Powershell: How do I retrieve the NextToken

久未见 提交于 2019-12-13 02:01:07
问题 Where do I retrieve the NextToken from when using the AWS Powershell CmdLets? For example when I call Get-CDDeploymentList I need to supply the NextToken to retrieve the next set of deployment IDs. However the Get-CDDeploymentList command only returns an array of deployment IDs and not a NextToken. 回答1: The NextToken is contained in the $AWSHistory.LastServiceResponse variable. In the case of the Get-CDDeploymentList command the LastServiceResponse will contain the properties Deployments and

How can I count running EC2 Instances?

余生长醉 提交于 2019-12-12 23:57:26
问题 I'm looking for a very basic script to count the number of running EC2 instances at AWS using PowerShell. I have found several methods but for some reason when I try them, I do not get the results I expect. The closest I have is this: $instancestate = (get-ec2instance).instances.state.name $instancestate which returns: stopped running stopped stopped running (the list goes on for about 80 instances) I wish to have a response that counts those which are running. 回答1: I'm not sure about others,

How can I set the Cache-Control when using Write-S3Object?

霸气de小男生 提交于 2019-12-11 02:52:31
问题 I am using Windows Powershell for AWS and I have tried the following: Write-S3Object -BucketName 'user-ab-staging' -KeyPrefix 'content/css' -Folder 'content/css' -SearchPattern '*.css' -Metadata @{"Cache-Control" = "Value"} -CannedACLName PublicRead It gives me a very strange error and only tries to load one css file: Uploaded 1 object(s) to bucket 'user-ab-staging' from 'C:\g\ab-user\WebUserApp\content\css' with keyprefix 'content/css' Write-S3Object : At line:1 char:1 + Write-S3Object ` + ~

How to upload all files of a specific type to S3 Bucket?

北城以北 提交于 2019-12-08 16:53:30
问题 When I do this: foreach ($f in (Get-ChildItem -filter "*.flv")){ Write-S3Object -BucketName bucket.example -File $f.fullName -Key $f.name -CannedACLName PublicRead } I get this error: Write-S3Object : At line:1 char:51 + foreach ($f in (Get-ChildItem -filter "*.flv")){ Write-S3Object -BucketName xx. ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Objec t],

AWS Powershell to retrieve AWS account number

久未见 提交于 2019-12-08 15:33:16
问题 Does anyone know how to get AWS account number using AWS Powershell? Doesn't look like there's an API available for that. 回答1: Not directly. However, your Account ID is a part of the Arn of resources that you create... and those that are automatically created for you. Some resources will also list you as an OwnerId. The Default Security Group is automatically created for you in each region, and cannot be deleted. This makes it a reliable candidate for retrieving our account Id. Example: PS C:

How to download files from s3 service to local folder

我们两清 提交于 2019-12-05 21:40:49
问题 I have requirement to download files from simple storage service to local folder and count the no.of files in local folder and check against simple storage service then send mail with the number of files. I tried to download files from simple storage service but I am getting error like get-s3object commandnotfoundexception . How do I resolve this issue? Code reference I have taken # Your account access key - must have read access to your S3 Bucket $accessKey = "YOUR-ACCESS-KEY" # Your account

How to encrypt data using KMS key in AWS Powershell script

 ̄綄美尐妖づ 提交于 2019-12-05 21:28:47
I am trying to encrypt a text using AWS KMS and creating a powershell script. So I used New-KMSDataKey to encrypt my KMS master key which in output returns plaintextDataKey and ciphertextblob . Now I am using plaintextDataKey to encrypt my plaintext using Invoke-KMSEncrypt but I get Invalid Operation error as shown below: Below is my script: param([string]$zonesecret, [string]$KMSKey, [string]$Keyspec, [string]$region= 'us-east-1', [string]$AccessKey, [string]$SecretKey) # splat $splat = @{KeyId=$KMSKey; KeySpec=$Keyspec; Region=$region} # generate a data key $datakey = New-KMSDataKey @splat

How can I get AWS Instance Tags in user-data?

随声附和 提交于 2019-11-30 19:00:27
问题 I use aws ec2 userdata with windows powershell scripts. I need instance bootstrapping. My idea is: EC2 instance tag adds.It's key name "Version", it's value "1.0.0.158-branchname" I have tried to get version tag value in userdata. I checked aws http api. It can't return tags. I wrote simple powershell scripts: $instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id") aws ec2 describe-tags --filters $filter --query 'Tags[*]' I can get