AWS SNS error - Invalid parameter while publishing message using aws-cli - amazon-web-services

I am working with AWS SNS services and completed the initial setup as the AWS documentation. I just needed to test it using aws-cli. So I used the following command to publish a test message to SNS topic from my local PC.
aws sns publish --topic-arn "arn:aws:sns:us-east-1:xxxxxxxxxxx:test-notification-service" --message "Hello, from SNS"
However, I got stuck on the following generic error. It just says Invalid Parameter. I have configured the ~/.aws/credentials as needed.
An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: TopicArn

The issue is due to cross-region. You AWS-CLI default region might be different to the region your SNS service location.
Check your AWS-CLI location and make sure you are in the same region as your SNS.
To check your region in AWS CLI use:
aws configure get region
To configure your AWS region you can use the command:
aws configure set region <region-name>
https://docs.aws.amazon.com/cli/latest/reference/configure/set.html

You can just add region parameter --region us-east-1 to your command:
aws sns publish --topic-arn "arn:aws:sns:us-east-1:xxxxxxxxxxx:test-notification-service" --message "Hello, from SNS" --region us-east-1

Related

How to detect AWS ECR public repositories using Cloud Custodian?

I'm new to Cloud Custodian and have the few doubts specific to using it for AWS.
I ran the following policy (no filters and actions present) so that I could get all the options for using as keys in value type filters :
policies:
- name: CheckPublicECRRepo
resource: ecr
The output was a detailed list of all the AWS ECR private repositories in my account which is exactly same as running aws ecr describe-repositories --region <region>.
So,
How AWS CLI command responses relate to those from running Cloud Custodian commands? Are they both calling same APIs? If yes, which API is being called here exactly?
How can I write a Cloud Custodian policy to detect AWS ECR public repositories? I'm getting the desired output by running this AWS CLI command : aws ecr-public describe-repositories --region us-east-1.
ecr-public resource does not seem to be supported yet. So I would either submit a feature request here or I would try to code the missing feature and contribute it.

Unable to add bulk contacts in AWS SES using cli

I am trying to run a simple command from aws documentation to upload the contacts.csv from S3 bucket to SES, while trying to do so, am constantly getting the error:
An error occurred (InternalFailure) when calling the CreateImportJob operation (reached max retries: 15): None
I have awscli 2.1.38 installed
The command I have used to transfer bulk contacts from an S3 bucket object to SES from documentation is:
aws sesv2 create-import-job \
--import-destination "{\"ContactListDestination\": {\"ContactListName\":\"ExampleContactListName\", \"ContactListImportAction\":\"PUT\"}}" \
--import-data-source "{\"S3Url\": \"s3://wwsexampletest/email-test\",\"DataFormat\": \"CSV\"}" --profile sameer```
Let me know, if you can run this command in your account. FYI, my SES is out of Sandbox.

Create security group at CLI, getting InvalidVpcID.NotFound The vpc ID does not exist

Trying to issue:
$ aws ec2 create-security-group --group-name Grp1 --description Grp1 --vpc-id vpc-0e6f748e8c01534bc
But I get
An error occurred (InvalidVpcID.NotFound) when calling the CreateSecurityGroup operation:
The vpc ID 'vpc-0e6f748e8c01534bc' does not exist
That vpc does exists, but it isn't being recognized.
It is in a different region.
I can't specify region in the command.
How do I get around that?
When you do some command on the aws cli, you can submit the region option as follows.
aws cli <some code> --region <region>
The cli options are listed in the aws documentation.

Try to get details from AWS beanstalk configration files

I am adding SNS to applications on AWS Beanstalk. I want to know which SNS topics the application/environment is attaching to. I tried
aws --region us-east-1 elasticbeanstalk describe-environments
It only gets a very vague file telling me the app is associated with one sns but no name no arn. Also, my ARM role has no access to the AWS Configuration.
Any thoughts?
My mistake. The command actually shows the detailed configuration info.

aws cli signature version 4

I want to move all my data from Bucket1 of account A to Bucket2 of account B.
For this:
I downloaded AWS CLI for Windows.
Entered IAM credentials using command aws configure (these credentials are from account B)
Run command to sync buckets: aws s3 sync s3://Bucket1 s3://Bucket2
I received following error:
fatal error: An error occured (InvalidRequest) when calling the ListObject operation: You are attempting to operate on a bucket in a region that requires Signature Version 4. You can fix this issue by explicitly providing the correct region location using the --region argument, the AWS_DEFAULT_REGION environment variable, or the region variable in the AWS CLI configuration file. You can get the bucket's location by running "aws s3api get-bucket-location --bucket BUCKET".
How to tackle this error?
aws --version
aws-cli/1.11.61 Python/2.7.9 windows/8 botocore/1.5.24
My S3 url was like :https://console.aws.amazon.com/s3/home?region=us-east-1
so I supposed that us-east-1 is my region but actually it was not!
I used AWS command to find Bucket2 region and it told me a different region.
Then I used this command aws s3 sync s3://Bucket1 s3://Bucket2 --region Asia Pacific (Mumbai) and everything worked fine!
Look for the correct region of the bucket (see attached image).
Try the command below by specifying the correct region:
aws s3 ls --region us-west-2
S3 is global - don't let that mislead you.