Calling Rekognition using AWS CLI - amazon-web-services

I have the AWS CLI installed on Windows and am using the Windows command prompt.
I am trying to use Rekognition but I cannot seem to get any commands working. The closest I have gotten is with:
aws rekognition detect-faces --image S3Object=\{Bucket=innovation-bucket,Name=image.jpg,Version=1\} --attributes "ALL" --region us-east-1
This results in:
Error parsing parameter '--image': Expected: ',', received: '}' for input: S3Object={Bucket=innovation-bucket,Name=image.jpg,Version=1}
Why is it expecting a comma?
EDIT:
When I try the format from the documentation I also get errors:
aws rekognition detect-faces --image '{"S3Object":{"Bucket":"innovation-bucket","Name":"image.jpg"}}' --attributes "ALL" --region us-east-1
Error parsing parameter '--image': Expected: '=', received ''' for input: '{"S3Object":{"Bucket":"innovation-bucket","Name":"image.jpg‌​"}}'

1) Your AWS CLI should be something like below, refer this documentation:
aws rekognition search-faces-by-image \
--image '{"S3Object":{"Bucket":"bucket-name","Name":"Example.jpg"}}' \
--collection-id "collection-id" \
--region us-east-1 \
--profile adminuser
2) If your AWS CLI installed on windows box, make sure you change "the single quotes to double quotes and the double quotes to escaped quotes"

Related

Cannot seem to get format of AWS Rekognition right in AWS CLI

Tried running AWS Rekognition in AWS CLI and got the following error
Error parsing parameter '--image': Invalid JSON: Expecting value: line 1 column 48 (char 47)
Also tried adjusting the " and ' but got the same error message. Appreciate all the help!
Code as follows:
aws rekognition index-faces --image "{\"S3Object\":{\"Bucket\":\"xxx\",\"Name\":"image.PNG"}}" --collection-id "\xxx"\ --detection-attributes \"ALL\" --external-image-id \"xxx\" --region us-west-2
Thanks in advance!
Here is a command I have successfully used:
aws rekognition index-faces \
--collection-id Trainers \
--image "S3Object={Bucket=my-bucket,Name=John.jpg}" \
--detection-attributes ALL \
--external-image-id John

aws cli create-snapshot fails

Trying to create snapshot of ebs volume. I have the below command in aws cli windows
aws --profile ade --region us-east-1 ec2 create-snapshot --volume-id vol-
012709ebb854c5fdd --description 'c-drive of i-00ca23fae0887e018' --tags-
specifications 'ResourceType=snapshot,Tags=[{Key=Product,Value=csf},
{Key=Service,Value=datamigration},{Key=Name,Value=cdrive-dms},
{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]'
I get response:
Uknown options: --tag-specifications, ResourceType=snapshot,Tags[{Key=Product,Value=csf},{Key=Service,Value=datamigration},{Key=Name,Value=cdrive-dms},{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]
It's got to be a simple syntax mistake...can anybody spot it? I've tried switching single quotes to double quotes and vice-versa.
Thank you.
The syntax that ended up working for me was:
aws --profile ade --region us-east-1 ec2 create-snapshot --volume-id vol-
012709ebb854c5fdd --description "c-drive of i-00ca23fae0887e018" --tag-specification
'ResourceType=snapshot,Tags=[{Key=Product,Value=csf},{Key=Service,Value=datamigration},
{Key=Name,Value=cdrive-dms},{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]'
tag-specification

Access updated lambda version from command: `aws lambda publish-version`

My CI pipeline will do two things
generate new lambda version and publish
Update an alias to point at that new version
This will be done via cli commands. My question is, how do I access the version number that been generated from the first command. It is returned and posted to the CLI. Can this be access easily via some nifty was command or will I have to parse it myself?
e.g.
version=$(aws lambda publish-version \
--function-name test_lambda --description "updated via cli" --region eu-west-1 \
--query Version \
--output text)
See Controlling Command Output from the AWS Command Line Interface page of AWS CLI User Guide, specifically How to Filter the Output with the --query Option and Text Output Format
This works but still curious if there is a better way.
version=$(aws lambda publish-version --function-name test_lambda --description "updated via cli" --region eu-west-1| jq '.Version')
NEW_LAMBDA_VERSION=$(aws lambda list-versions-by-function --function-name $LAMBDA_NAME_FOR_DEPLOY --no-paginate --query "max_by(Versions, &to_number(to_number(Version) || '0'))")
NEW_LAMBDA_VERSION=$(echo $NEW_LAMBDA_VERSION | jq -r .Version)
echo $NEW_LAMBDA_VERSION
In this case, I use on .gitlab-ci.yml.

aws cli --query doesn't filter output in windows command promt

I am following the documentation to use the --query option in aws cli. However it doesn't work for me at all. I have defined profiles because I have several accounts to pull the data. If I omit the --query, it returns the data successfully. Any insight into this please?
Thank you
> aws --version
aws-cli/1.14.8 Python/3.6.3 Windows/10 botocore/1.8.12
> aws ec2 describe-volumes --profile TEST1 --region us-east-1 --query 'Volumes[0]'
"Volumes[0]"
> aws ec2 describe-volumes --profile TEST1 --region us-east-1
{
"Volumes": [
{
"Attachments": [ ....
Change from single quotes to double quotes:
aws ec2 describe-volumes --profile TEST1 --region us-east-1 --query "Volumes[0]"
As soon as i switched to powershell, it works successfully. Although I am not sure why it requires using powershell.

Where to find Endpoint in creating aws-cli bots without using amazon-lex?

I'm trying to create a chatbot using aws-cli .Going through the Steps in Documentation in https://docs.aws.amazon.com/lex/latest/dg/gs-create-flower-types.html
I couldn't understand what endpoint did it mean in the documentation as shown in the syntax.
aws lex-models put-slot-type \
--region region \
--endpoint endpoint \
--name FlowerTypes \
--cli-input-json file://FlowerTypes.json
What is the endpoint in the above syntax?
You can find the list of endpoints for Lex at this link
For your current case, https://models.lex.us-east-1.amazonaws.com/ will work as endpoint, given that your region is us-east-1.
Below code will work if you are using Windows machine:
aws lex-models put-slot-type ^
--region us-east-1 ^
--endpoint https://models.lex.us-east-1.amazonaws.com/ ^
--name FlowerTypes ^
--cli-input-json file://FlowerTypes.json
Keep the input json file in the same folder where you have opened the CLI.