Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
delivery protocols. For more information about this product see
`http://aws.amazon.com/sns`_. For detailed information about
Amazon SNS features and their associated API calls, see the
`Amazon SNS Developer Guide`_.
We also provide SDKs that enable you to access Amazon SNS from
your preferred programming language. The SDKs contain
functionality that automatically takes care of tasks such as:
cryptographically signing your service requests, retrying
requests, and handling error responses. For a list of available
SDKs, go to `Tools for Amazon Web Services`_.
"""
DefaultRegionName = boto.config.get('Boto', 'sns_region_name', 'us-east-1')
DefaultRegionEndpoint = boto.config.get('Boto', 'sns_region_endpoint',
'sns.us-east-1.amazonaws.com')
APIVersion = boto.config.get('Boto', 'sns_version', '2010-03-31')
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None, path='/',
security_token=None, validate_certs=True,
profile_name=None):
if not region:
region = RegionInfo(self, self.DefaultRegionName,
self.DefaultRegionEndpoint,
connection_cls=SNSConnection)
self.region = region
super(SNSConnection, self).__init__(aws_access_key_id,
aws_secret_access_key,
is_secure, port, proxy, proxy_port,
from boto.resultset import ResultSet
from boto.ec2.image import Image, ImageAttribute
from boto.ec2.instance import Reservation, Instance, ConsoleOutput
from boto.ec2.keypair import KeyPair
from boto.ec2.address import Address
from boto.ec2.volume import Volume
from boto.ec2.snapshot import Snapshot
from boto.ec2.zone import Zone
from boto.ec2.securitygroup import SecurityGroup
from boto.ec2.regioninfo import RegionInfo
from boto.ec2.reservedinstance import ReservedInstancesOffering, ReservedInstance
from boto.exception import EC2ResponseError
class EC2Connection(AWSQueryConnection):
APIVersion = boto.config.get('Boto', 'ec2_version', '2009-03-01')
DefaultRegionName = boto.config.get('Boto', 'ec2_region_name', 'us-east-1')
DefaultRegionEndpoint = boto.config.get('Boto', 'ec2_region_endpoint',
'us-east-1.ec2.amazonaws.com')
SignatureVersion = '2'
ResponseError = EC2ResponseError
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None):
"""
Init method to create a new connection to EC2.
B{Note:} The host argument is overridden by the host specified in the boto configuration file.
"""
if not region:
parser.add_argument('--region',
help='Override default region for emr connection')
parser.add_argument('--profile',
help='Profile to use for emr connection')
parser.add_argument('--verbose', '-v', action="store_true",
help='Log to console')
parser.add_argument('--debug', '-d', action="store_true",
help='Enable debug logging')
args = parser.parse_args()
## Set region if defined, otherwise fallback on profile
## Default to ~/.aws/credentials, then .boto
if args.region:
region = args.region
elif args.profile:
region = boto.config.get('%s' % args.profile, 'region', \
boto.config.get('profile %s' % args.profile, 'region', None))
else:
region = boto.config.get(DEFAULT_AWS_SEC, 'region', \
boto.config.get(DEFAULT_BOTO_SEC, 'region', None))
if args.uuid:
uuid = args.uuid
else:
uuid = int(time())
rundir = "/%s" % uuid
print "RunDir: hdfs://%s" % rundir
## Setup logging
logger = logging.getLogger('rsync')
logger.setLevel(logging.INFO)
def auth_login():
"""
Saves user authentication data for AWS S3 using boto. This does not
verify your credentials.
Usage: widely auth:login
"""
print('Enter your AWS credentials.')
aws_access_key_id = raw_input('Access Key ID: ')
aws_secret_access_key = raw_input('Secret Access Key ID: ')
try:
boto.config.add_section('Credentials')
except DuplicateSectionError:
pass
# TODO: Check for valid credentials ?
boto.config.set(
'Credentials',
'aws_access_key_id',
aws_access_key_id
)
boto.config.set(
'Credentials',
'aws_secret_access_key',
aws_secret_access_key
)
boto_config_file = open(os.path.expanduser('~/.boto'), 'w')
def auth_login():
"""
Saves user authentication data for AWS S3 using boto. This does not
verify your credentials.
Usage: widely auth:login
"""
print('Enter your AWS credentials.')
aws_access_key_id = raw_input('Access Key ID: ')
aws_secret_access_key = raw_input('Secret Access Key ID: ')
import boto
from ConfigParser import DuplicateSectionError
try:
boto.config.add_section('Credentials')
except DuplicateSectionError:
pass
## Check for valid credentials ?
boto.config.set('Credentials',
'aws_access_key_id',
aws_access_key_id)
boto.config.set('Credentials',
'aws_secret_access_key',
aws_secret_access_key)
import os
boto_config_file = open(os.path.expanduser('~/.boto'), 'w')
boto.config.write(boto_config_file)
print('Authentication successful.')
def _populate_keys_from_metadata_server(self):
# get_instance_metadata is imported here because of a circular
# dependency.
boto.log.debug("Retrieving credentials from metadata server.")
from boto.utils import get_instance_metadata
timeout = config.getfloat('Boto', 'metadata_service_timeout', 1.0)
attempts = config.getint('Boto', 'metadata_service_num_attempts', 1)
# The num_retries arg is actually the total number of attempts made,
# so the config options is named *_num_attempts to make this more
# clear to users.
metadata = get_instance_metadata(
timeout=timeout, num_retries=attempts,
data='meta-data/iam/security-credentials/')
if metadata:
creds = self._get_credentials_from_metadata(metadata)
self._access_key = creds[0]
self._secret_key = creds[1]
self._security_token = creds[2]
expires_at = creds[3]
# I'm assuming there's only one role on the instance profile.
self._credential_expiry_time = datetime.strptime(
expires_at, "%Y-%m-%dT%H:%M:%SZ")
:rtype: :class:`boto.ec2.ELBConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
"""
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
class ELBConnection(AWSQueryConnection):
APIVersion = boto.config.get('Boto', 'elb_version', '2011-11-15')
DefaultRegionName = boto.config.get('Boto', 'elb_region_name', 'us-east-1')
DefaultRegionEndpoint = boto.config.get('Boto', 'elb_region_endpoint',
'elasticloadbalancing.amazonaws.com')
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=False, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None, path='/',
security_token=None):
"""
Init method to create a new connection to EC2 Load Balancing Service.
.. note:: The region argument is overridden by the region specified in
the boto configuration file.
"""
if not region:
region = RegionInfo(self, self.DefaultRegionName,
self.DefaultRegionEndpoint)
def _HasGceCreds():
return config.has_option('GoogleCompute', 'service_account')
def __init__(self):
ScriptBase.__init__(self)
self.wdir = boto.config.get('Pyami', 'working_dir')
self.log_file = '%s.log' % self.instance_id
self.log_path = os.path.join(self.wdir, self.log_file)
boto.set_file_logger(self.name, self.log_path)
self.src_name = boto.config.get(self.name, 'src_bucket')
self.dst_name = boto.config.get(self.name, 'dst_bucket')
self.replace = boto.config.getbool(self.name, 'replace_dst', True)
s3 = boto.connect_s3()
self.src = s3.lookup(self.src_name)
if not self.src:
boto.log.error('Source bucket does not exist: %s' % self.src_name)
dest_access_key = boto.config.get(self.name, 'dest_aws_access_key_id', None)
if dest_access_key:
dest_secret_key = boto.config.get(self.name, 'dest_aws_secret_access_key', None)
s3 = boto.connect(dest_access_key, dest_secret_key)
self.dst = s3.lookup(self.dst_name)
if not self.dst:
def load_config(show_output=False):
config_filename = path.join(directory, 'config')
aws_dirty = False
if not boto.config.has_option('Credentials', 'aws_access_key_id'):
aws_access_key_id = getpass.getpass('AWS Access Key ID: ')
boto.config.save_user_option('Credentials', 'aws_access_key_id', aws_access_key_id)
aws_dirty = True
if not boto.config.has_option('Credentials', 'aws_secret_access_key'):
aws_secret_access_key = getpass.getpass('AWS Secret Access Key: ')
boto.config.save_user_option('Credentials', 'aws_secret_access_key', aws_secret_access_key)
aws_dirty = True
if aws_dirty:
print "-----> AWS configuration written to {}".format(boto.pyami.config.UserConfigPath)
else:
if show_output: print "-----> AWS configuration unchanged, see `{}`".format(boto.pyami.config.UserConfigPath)
vpc = boto.connect_vpc()
try:
with open(config_filename, 'r') as config_file:
config = json.loads(config_file.read())
except IOError:
config = default_config()
dirty = False