Search code examples
amazon-web-servicespowershellencryptioncommand-line-interfaceamazon-kms

AWS Encryption SDK documentation example


I was following the AWS documentation example for envelope encryption in which there is a command for PowerShell. The command doesn't work on my PC so I need someone to help me figure out why. Below is the link to the documentation;

https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/crypto-cli-examples.html

Below is the error I get when I follow the instructions in the documentations;

PS C:> $CmkArn = arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89 arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89 : The term 'arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:11

  • $CmkArn = arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a ...
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (arn:aws:kms:us-...17-f5bba5e6af89:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Solution

  • The syntax in their example is wrong, this is how it should be written:

     # To run this example, replace the fictitious key ARN with a valid value.
    PS C:\> $CmkArn = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
    
    PS C:\> aws-encryption-cli --encrypt `
                               --input Hello.txt `
                               --master-keys key=$CmkArn `
                               --metadata-output $home\Metadata.txt `
                               --encryption-context purpose=test `
                               --output .
    

    The fictitious ARN needs quotes around it.