Dynamo DB AWS cli getting error - amazon-web-services

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

Related

Error "Unknown options: AutoImportPolicy=DELETED], AutoImportPolicy=CHANGED" while creating AWS FSx create-data-repository-association

I am getting error while adding auto-import-policy when creating AWS FSx create-data-repository-association
FSX Lustre config is:
Storage type: SSD
Deployment type: Persistent 2
Lustre version: 2.12
Success: The below command is successful
aws --region region_name fsx create-data-repository-association --file-system-id fs-xxxxxxxxxxx --batch-import-meta-data-on-create --file-system-path /ns1/ --data-repository-path s3://s3_bucket_path --s3 AutoImportPolicy={Events=[NEW]},AutoExportPolicy={Events=[NEW]}
Error: throwing error when taking multiple options in the list of the AutoImportPolicy
aws --region region_name fsx create-data-repository-association --file-system-id fs-xxxxxxxxx --batch-import-meta-data-on-create --file-system-path /ns1/ --data-repository-path s3://s3_bucket_path --s3 AutoImportPolicy={Events=[NEW,CHANGED,DELETED]}
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: AutoImportPolicy=DELETED], AutoImportPolicy=CHANGED
I tried the below options but none of them are successful
--s3 AutoImportPolicy={Events=['NEW','CHANGED','DELETED']}
--s3 AutoImportPolicy={Events=["NEW","CHANGED","DELETED"]}
--s3 AutoImportPolicy={Events=[NEW|CHANGED|DELETED]}
--s3 AutoImportPolicy={Events=[NEW_CHANGED_DELETED]}
but none of the above options worked
Expecting: I am expecting to create the data-repository-association whose AutoImportPolicy should be New,Changed & deleted
the issue is fixed by using the below command:
aws --region ${AWS_REGION} fsx create-data-repository-association \
--batch-import-meta-data-on-create \
--file-system-id ${fsx_id} \
--file-system-path /ns1/ \
--data-repository-path ${s3_dra} \
--s3 "AutoImportPolicy={Events=[NEW,CHANGED,DELETED]},AutoExportPolicy={Events=[NEW,CHANGED,DELETED]}"

No way to Get-Item in powershell?

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\`"}}'

Error parsing parameter '--targets': Expected: '=', received: '{' for input:

I am creating a crawler through AWS CLI in Glue, but facing issue.
Here's the CLI Command that i use
aws glue create-crawler \
--name "mytestcrawlernew" \
--role "arn:aws:iam::role/AWSGlueServiceRole-AWSGlueServiceRole" \
--database-name "mydb" \
--description "This is the test Crawler" \
--targets "JdbcTargets":{"ConnectionName":"RS_Connection"}
Am i doing anything wring, cause i am facing the subjected issue
On the official documentation here, you can have a look at the proper syntax like in this example:
aws glue create-crawler
--name comprehend-analysis-crawler
--role glue-iam-role-arn
--targets S3Targets=[
{Path="s3://DOC-EXAMPLE-BUCKET/sentiment-results"},
{Path="s3://DOC-EXAMPLE-BUCKET/entities-results"}]
--database-name comprehend-results
Look carefully that you are stating --targets "JdbcTargets" and it looks like it should be --targets JdbcTargets=[

aws cli --profile expected one parameter

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

How pass json as parameter to aws cli?

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.