hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 10y, 125d ago [edited]

Thanks!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 10y, 90d ago [edited]

Thanks a lot buddy for this basic yet important lesson.

Python 3 picks up the IAM role and other stuff on its own, however I faced challenges with Python 2.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 10y, 77d ago [edited]

Great Information ! This is what I was looking for !! Thank you !

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

TXO6AksL 10y, 71d ago [edited]

Awesome !! Exactly the info that was needed !

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 10y, 43d ago [edited]

If I use aws configure to configure the details, do I still need to pass the region explicitly?

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 10y, 43d ago

You can set a default region in the aws config (.aws/config) for your profile.

Then instead of passing a region, you can pass a profile name.

Here is a class I wrote to manage boto connections:

In it you can see how I get the default region from the profile.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 10y, 28d ago [edited]

I am using Boto3 resource to send push notification to iOS devices.

It is working fine but issue is that I am not able to show badge count on the iOS App and also not able to pass any value for sound effect for new notifications.

My code below:

sns = boto3.resource(
        'sns',
        region_name='AWS_REGION_NAME',
        aws_access_key_id='AWS_ACCESS_KEY',
        aws_secret_access_key='AWS_SECRET_ACCESS_KEY'
      )

user_endpoint_arn = 'DEVICE_ENDPOINT_ARN'

platform_endpoint = sns.PlatformEndpoint(endpoint_arn)

platform_endpoint.publish(Message='notification message')

What should be added here to have sound effect for new notifications and also for badge count (count for unread notifications) on the installed APP icon?

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 10y, 28d ago

Sorry I don't use this part of the API so I can't help. Hopefully somebody else can chime in.

Otherwise, I would ask AWS support or the Boto3 github issue tracker.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 357d ago [edited]

Thanks, It helped me to set my 'ses' region to eu-west-1 since aws has no ses in ap-southeast

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 356d ago

Your welcome! Great use case.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 293d ago [edited]

Thank u so much!

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 293d ago

You are welcome!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 275d ago [edited]

totally helped me out today! I looked at boto docs first and couldn't figure it out

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 275d ago

You are very welcome!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 266d ago [edited]

Thanks dude! Was wondering why the AWS_REGION env variable wasn't being honored and couldn't use a boto config.

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 265d ago

Cool, yeah, I stopped using ENV vars and either use flags or I use the ~/.aws/config with profiles.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 254d ago [edited]

A related option, when in ec2, assuming you want to connect to whatever region the ec2 instance is running in (thus the region isn't hard coded):

import json
import boto3
import urllib2

durl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
document = json.loads(urllib2.urlopen(durl).read())
client = boto3.client('cloudwatch', region_name=document['region'])
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 232d ago [edited]

Thank you Russell. didn't know lambda could be executed in all regions by configuring regions. gonna help me reduce the time to spend on making lambda function in every region!!

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 232d ago

Yeah, makes perfect sense if you want to maintain the same lambda script in multiple regions, iterate over all regions and upload latest.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 198d ago

How to pass aws_access_key_id,aws_secret_access_key,region in client I am working on elb please help

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 162d ago

I had to search the whole internet to find such a simple answer that how can i pass the aws credential on boto3 resource. Saved my day man!!!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 6d ago [edited]

Hi, when I use:

>>> import boto3
>>> rds = boto3.setup_default_session(region_name='us-west-2')
>>> rds = boto3.client('rds')

It raises:

NoCredentialsError botocore.exceptions.NoCredentialsError:

Unable to locate credentials

What should I do?

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 9y, 6d ago [edited]

Hi, this error message means boto3 didn't find API credentials. To fix this you need to either setup:

  • A profile in your aws config file (typically located in ~/.aws/config)

  • Environment vars: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

Check out my quickstart for the botoform project here for more details.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 9y, 3d ago

Thank you so much. It helps me.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

jmbW8tGZ 8y, 353d ago [edited]

Thanks for this post. I did not know that Lambda function in US region can access resource in Asia region like this...

session = Session(aws_access_key_id='xxx', aws_secret_access_key='x+xx/xx')
ec2 = session.resource('ec2', region_name='ap-south-1')
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 8y, 275d ago

Thank you :)

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 8y, 222d ago

Thanks, this was great!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 8y, 133d ago

Thank you for sharing. Nicely presented. This Saved me.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 341d ago

Thanks Russell.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 190d ago

Very helpful!! :D

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 95d ago

Hi all Cool and helpful article. Now I'm trying to dive a little deeper The task is how to use region_name as list of defined regions. For example, find all instances across AWS with specific tag.

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 7y, 95d ago [edited]

You might be able to steal some code from a tool I wrote called atmosphere.

It loops over all AWS profiles, over all regions for each profile, and does some look ups.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 85d ago

Thanks, it helped.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

Bw9c3zPj 7y, 79d ago

Hi, I would like to pass region input as variable interactively. Like how python get it as raw_input() So, how do I do that in boto3

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 7y, 79d ago

I prefer to use flags than interactive prompts. That said, this totally works:

>>> import boto3
>>> region_name = raw_input("region: ")
region: us-west-2
>>> rds = boto3.client('rds', region_name=region_name)
remark link parent
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

Bw9c3zPj 7y, 78d ago

Thanks Russell..!!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 52d ago

Hey Buddy, you made my 1 week work resolved. Thanks. AWS document keeps you busy reading, till you die or finish their document.

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 7y, 52d ago

Welcome.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 7y, 45d ago

Thanks!

remark link
hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

russell 7y, 45d ago

Welcome!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 6y, 285d ago

thanks!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

aduYzOf7 6y, 202d ago

Very nice thanks!! can anyone chime in how to do this on a one liner instead of 2 lines? boto3.setup_default_session(profile_name='account1') boto3.setup_default_session(region_name='eu-west-2')

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 6y, 89d ago

hi...i am trying to access a lambda function which is in eu-west-1 using api gateway.the api gateway , i dont know how created in us-east-1...how should i solve this?I cannot able to create api in the same region as lambda fn

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

mSwornyB 5y, 249d ago

This is great, just what I was looking for, do you know of a way to find which specific instances of services/resources are using which using roles?

I'm trying to write a little program that will audit our role usage based on the instances of EC2 and other services using the roles.

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!

unverified 5y, 228d ago

Thanks!!!!

hide preview ▲show preview ▼

What's next? verify your email address for reply notifications!