How to use the boto3.client function in boto3

To help you get started, we’ve selected a few boto3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spulec / moto / tests / test_ec2 / test_instances.py View on Github external
def test_run_multiple_instances_in_same_command():
    instance_count = 4
    client = boto3.client("ec2", region_name="us-east-1")
    client.run_instances(
        ImageId="ami-1234abcd", MinCount=instance_count, MaxCount=instance_count
    )
    reservations = client.describe_instances()["Reservations"]

    reservations[0]["Instances"].should.have.length_of(instance_count)

    instances = reservations[0]["Instances"]
    for i in range(0, instance_count):
        instances[i]["AmiLaunchIndex"].should.be(i)
github awslabs / aws-data-wrangler / testing / test_awswrangler / test_emr.py View on Github external
def cloudformation_outputs():
    response = boto3.client("cloudformation").describe_stacks(StackName="aws-data-wrangler-test-arena")
    outputs = {}
    for output in response.get("Stacks")[0].get("Outputs"):
        outputs[output.get("OutputKey")] = output.get("OutputValue")
    yield outputs
github awslabs / aws-sam-cli / tests / smoke / download_sar_templates.py View on Github external
def _download_templates(app_id, template_file_path):
    sar = boto3.client("serverlessrepo")
    response = sar.get_application(ApplicationId=app_id)

    template_url = response["Version"]["TemplateUrl"]

    with open(template_file_path, "wb") as fp:
        r = requests.get(template_url, stream=True)
        for chunk in r.iter_content(chunk_size=128):
            fp.write(chunk)
github metaspace2020 / metaspace / metaspace / engine / sm / engine / formula_centroids.py View on Github external
self._ion_centroids_path = '{}/v2/{}/{}_{}/{}'.format(
                self._sm_config['isotope_storage']['path'],
                self._isocalc.n_peaks,
                self._isocalc.instrument,
                self._isocalc.sigma,
                self._isocalc.charge,
            )
        self._parquet_file_names = ['centroids.parquet', 'formulas.parquet']
        self._centroids_stored_on_s3 = self._ion_centroids_path.startswith('s3a://')
        if self._centroids_stored_on_s3:
            self._local_ion_centroids_path = Path('/tmp')
        else:
            self._local_ion_centroids_path = Path(self._ion_centroids_path)
        Path(self._local_ion_centroids_path).mkdir(parents=True, exist_ok=True)

        self._s3 = boto3.client(
            's3',
            self._sm_config['aws']['aws_default_region'],
            aws_access_key_id=self._sm_config['aws']['aws_access_key_id'],
            aws_secret_access_key=self._sm_config['aws']['aws_secret_access_key'],
        )
github aws / lumberyard / dev / Gems / CloudGemFramework / v1 / AWS / common-code / Utils / cgf_utils / aws_utils.py View on Github external
def get_cognito_pool_from_file(configuration_bucket, configuration_key, logical_name, stack):
    s3 = ClientWrapper(boto3.client('s3', current_region, config=Config(
        region_name=current_region, signature_version='s3v4', s3={'addressing_style': 'virtual'})))
    s3_key = configuration_key + '/cognito-pools.json'
    try:
        res = s3.get_object(Bucket=configuration_bucket, Key=s3_key)
        content = json.loads(res['Body'].read())
    except Exception as e:
        return ""
    key = ""
    if stack.is_deployment_access_stack:
        key = "DeploymentAccess"
    if stack.is_project_stack:
        key = "Project"

    return content.get(key, {}).get(logical_name, "")
github aws-samples / aws-developer-workshop / episode2 / scripts / compareFaces.py View on Github external
from __future__ import print_function

import boto3
from decimal import Decimal
import json
import urllib
import os

print('Loading function')
this_region = os.environ['AWS_DEFAULT_REGION'];
print("region: " + this_region)

sns = boto3.client('sns')
s3 = boto3.client('s3')
ddb = boto3.resource('dynamodb')
table = ddb.Table('rekognitionTable')
# Using the table that was created from CloudFormation
rekognition = boto3.client('rekognition', this_region)

# --------------- Helper Functions to call Rekognition APIs ------------------

def detect_faces(bucket, key):
    response = rekognition.detect_faces(Image={"S3Object": {"Bucket": bucket, "Name": key}})
    return len(response['FaceDetails'])

def compare_faces(bucket, sourcekey, targetkey, threshold=70):

    response = rekognition.compare_faces(
                    SourceImage={
                        'S3Object':{
github PaloAltoNetworks / aws / globalprotect-asg / scripts / init_portal.py View on Github external
import boto3
import logging
import json
import httplib
import xml.etree.ElementTree as et
import time
from urlparse import urlparse
from contextlib import closing
import ssl
import urllib2

ec2 = boto3.resource('ec2')
ec2_client = boto3.client('ec2')
lambda_client = boto3.client('lambda')
as_client = boto3.client('autoscaling')
events_client = boto3.client('events')
logger = logging.getLogger()
logger.setLevel(logging.INFO)


PortalMgmtIp = ""
PortalDPIp = ""
api_key = ""
gcontext = ""
job_id = ""
asg_name = ""

def init_portal_lambda_handler(event, context):
    global PortalMgmtIp
github 0x4D31 / honeyLambda / handler.py View on Github external
def load_config():
    """ Load the configuration from local file or Amazon S3 """

    # Check the environment variable for config type (local/s3)
    CONFIGFILE = os.environ['configFile']
    # Load config from S3
    if CONFIGFILE == "s3":
        BUCKET = os.environ['s3Bucket']
        KEY = os.environ['s3Key']
        s3 = boto3.client('s3')
        try:
            response = s3.get_object(Bucket=BUCKET, Key=KEY)
            data = response['Body'].read()
            conf = json.loads(data)
            logger.info("Config file loaded from S3")
        except Exception as err:
            logger.error(err)
            raise
    else:
        # Load config from local file
        with open('config.json') as config_file:
            conf = json.load(config_file)
            logger.info("Local config file loaded")

    return conf
github amaysim-au / docker-ecs-utils / scripts / deploy.py View on Github external
def upload_task_definition(task_definition):
    """Interpolates some values and then uploads the task definition to ECS

    Returns the task definition version ARN"""

    print("Generating environment variable configuration...")
    environment = generate_environment_object()
    for index, value in enumerate(task_definition['containerDefinitions']):  # pylint: disable=unused-variable
        task_definition['containerDefinitions'][index]['environment'] = environment
    print("Task definition generated:")
    print(json.dumps(task_definition, indent=2, default=str))

    print("Uploading Task Definition...")
    ecs = boto3.client('ecs')
    response = ecs.register_task_definition(**task_definition)
    task_definition_arn = response['taskDefinition']['taskDefinitionArn']
    print("Task Definition ARN: {}".format(task_definition_arn))
    return task_definition_arn
github NitorCreations / nitor-deploy-tools / n_utils / cf_bootstrap.py View on Github external
def _ask_elastic_ip(self):
        self.elastic_ip = "Elastic ip ({0}):\n1: allocate new\n"
        self.elastic_ips = []
        self.elastic_ip_default = lambda: "1"
        if "elastic_ip" not in self.ask_fields:
            self.ask_fields.append("elastic_ip")
        index = 2
        ec2 = boto3.client("ec2")
        eips = ec2.describe_addresses()
        if eips and "Addresses" in eips:
            for address in eips["Addresses"]:
                if "InstanceId" not in address:
                    self.elastic_ips.append(address['PublicIp'])
                    self.elastic_ip = self.elastic_ip + str(index) \
                        + ": " + address['PublicIp'] + "\n"
                    index = index + 1
        self.value_mappers["elastic_ip"] = _map_elastic_ip
        self.template_transformers.append(lambda myself: _set_first_parameter(myself.template,
                                                                              "paramEip",
                                                                              myself.elastic_ip))