So I've tried a few things now, one of which is AWS.Tools.DynamoDBv2 and nothing seems to work.
AWS CLI works in powershell to an extent, for example, the command "aws ec2 describe-instances..." works. However, "aws dynamodb get-item --table-name --key "{"primary-key":{"S":"myitem"}}" does not.
It returns the error stating that "{"primary-key":{"S":"myitem"}}" is an unknown option.
What am I doing wrong? Any help is appreciated.
aws dynamodb get-item --table-name --key "{"primarykey":{"S":"myitem"}}
aws :
At line:1 char:1
+ aws dynamodb get-item --table-name <mytable> --key "{ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: primary-key:{S:myitem}}
Edit:
Thanks for the help! This was really grinding my gears! As Abraham Zinala suggested, single quotes were necessary around the whole key object. Also, backslashes inside were necessary too:
--key '{\"primarykey\":{\"S\":\"myitem\"}}'
As #AbrahamZinala suggested, single quotes were necessary around the whole key object. Also, backslashes inside were necessary too:
--key '{\"primarykey\":{\"S\":\"myitem\"}}'
Also, for what it's worth, if using string interpolation, it would have to look like this:
--key '{\`"$primarykey\`":{\`"S\`":\`"$myitem\`"}}'
Related
I am trying to use --profile with aws-cli
$ aws s3 ls --profile profile360
Works good, but:
$ aws dynamodb scan --table-name dev_eventsApi_EventsTable --output > c:\temp\hevo.txt --profile profile360
results in
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument --output: expected one argument
I encounter cases where I have problems working with --profile
What am I doing wrong?
Define the type of output, for example, text or json. Try this.
aws dynamodb scan --table-name dev_eventsApi_EventsTable --output text --profile profile360 > c:\temp\hevo.txt
i've created a clustering model on sagemaker and i'm invoking it via CLI with this command:
aws sagemaker-runtime invoke-endpoint --endpoint-name myendpoint --body $mydata --content-type text/csv output.json --region eu-west-1
If my data starts with a negative number, i get an error
"usage: aws [options] [ ...] [parameters]
To see help text, you can run:
aws help
aws help
aws help
aws: error: argument --body: expected one argument"
While if it's a positive number, everything works. How can i escape the first minus of the data to make it work?
Thanks in advance
It looks like that aws cli is treating your input data as another option because negative sign and hyphen are the same.
Have you tried to use quotes before and after $mydata?
For example, instead of:
sagemaker-runtime invoke-endpoint --endpoint-name myendpoint --body -2,1,2 --content-type text/csv output.json --region eu-west-1
use:
sagemaker-runtime invoke-endpoint --endpoint-name myendpoint --body "-2,1,2" --content-type text/csv output.json --region eu-west-1
Did you use AWS Sagemaker's provided image for clustering? If you provided your own, you should be able to modify the inference code to expect the input data to have a header row. Then modify $mydata to include column headers which should avoid this issue you're seeing with negative numbers.
I am trying to update crawler using this command:
aws glue update-crawler --name my-crawler --configuration '{"Version":1.0,"CrawlerOutput":{"Partitions":{"AddOrUpdateBehavior":"InheritFromTable"}}}' --region us-west-2
As described here
Instead of update I got:
An error occurred (InvalidInputException) when calling the UpdateCrawler operation: Crawler configuration not valid: Error parsing JSON: Received JsonParseException: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'). Check that your JSON is well formed. For more information about the crawler configuration structure, see http://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-crawling.html.
The jsonlint tells me that json is ok.
What is wrong? How pass json as parameter for aws cli?
cli is used under windows 10
You have to escape the quotes under Windows:
aws glue update-crawler --name my-crawler --configuration "{\"Version\":1.0,\"CrawlerOutput\":{\"Partitions\":{\"AddOrUpdateBehavior\":\"InheritFromTable\"}}}" --region us-west-2
For Windows, you have to do some "special" escaping, which I've learned the hard way. Take the following JSON snippet...
{ "#t": "timestamp" }`
Here's how you'd enter it on Windows...
DOS
aws dynamodb scan --table-name MyTable --region "us-east-1" --profile dev --projection-expression "failureKey, #t" --expression-attribute-names "{ ""#t"": ""timestamp"" }"
For Powershell, it's a little different...
Powershell
aws dynamodb scan --table-name "MyTable" --region "us-east-1" --profile "dev" --projection-expression "failureKey, #t" --expression-attribute-names '{ \"#t\": \"timestamp\" }'
Used an example with a shorter JSON snippet, but you get the idea. Apply the same concept to your string based on the shell your using.
C:\Users\abhij\.aws\model>aws dynamodb put-item --table-name weatherstation_data --item '{"station_id":{"S":"000001"},"dateandtime" : {"S": "2015/12/25 00:00"},"temperature": {"N" : "0"}}' --profile loadmin
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: {S:, 2015/12/25 00:00},temperature:, {N, :, 0}}', :
You need to remove or escape all the whitespace in the JSON portion of the command. This is a common problem, which is why most of the examples in the aws dynamodb CLI tool docs show the use of a JSON file instead, like so:
aws dynamodb put-item --table-name weatherstation_data --item file://item.json --profile loadmin
Nevermind its the windows CMD thats giving the problem ran the same in linux it gives back the output
aws dynamodb put-item --table-name weatherstation_data --item '{"station_id":{"S":"000001"},"dateandtime" : {"S": "2015/12/25 00:00"},"temperature": {"N" : "0"}}' --profile loadmin
I'm attempting to call run-instances and pass the resulting instance IDs as the input to create-tags as a one-liner as follows:
aws ec2 run-instances \
--image-id ami-1234 \
--output text \
--query Instances[*].InstanceId | \
aws ec2 create-tags \
--tags 'Key="foo",Value="bar"'
When attempting this, I get the following:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument --resources is required
Is something like this possible or does one have to resort to using variables (or some other way I'm not thinking about)?
Additional Background
The motivation for asking this question is that something like this is possible with the AWS Tools for Windows PowerShell; I was hoping to accomplish the same thing with the AWS CLI.
Equivalent PowerShell example:
New-EC2Instance -ImageId ami-1234 |
ForEach-Object Instances |
ForEach-Object InstanceId |
New-EC2Tag -Tag #{key='foo';value='bar'}
It can be done by leveraging xargs -I to capture the instance IDs to feed it into the --resources parameter of create-tags.
aws ec2 run-instances \
--image-id ami-1234 \
--output text \
--query Instances[*].[InstanceId] | \
xargs -I {} aws ec2 create-tags \
--resources {} \
--tags 'Key="foo",Value="bar"'
Note that unlike the example in the original question, it's important to wrap the "InstanceId" portion of the --query parameter value in brackets so that if one calls run-instances with --count greater than one, the multiple instance IDs that get returned will be outputted as separate lines instead of being tab-delimited. See http://docs.aws.amazon.com/cli/latest/userguide/controlling-output.html#controlling-output-format