boto3

Python boto3 - Athena Query - start_query_execution - The security token included in the request is invalid

偶尔善良 提交于 2020-08-06 06:09:32
问题 My code to get Athena Query is self.athenaDataSource = "AwsCatalog" self.athenaDB = "prod_myapp_app" self.athenaResultBucket = "s3://s3-athena-prod-results/" and here i show I create client and call .start_query_execution clientAthena = boto3.client('athena', region_name=awsRegion) athenaQueryExecResp = clientAthena.start_query_execution( QueryString=self.athenaQuery, QueryExecutionContext={ 'Database': self.athenaDB }, ResultConfiguration={'OutputLocation': self.athenaResultBucket } ) print(

Python boto3 - Athena Query - start_query_execution - The security token included in the request is invalid

放肆的年华 提交于 2020-08-06 06:09:05
问题 My code to get Athena Query is self.athenaDataSource = "AwsCatalog" self.athenaDB = "prod_myapp_app" self.athenaResultBucket = "s3://s3-athena-prod-results/" and here i show I create client and call .start_query_execution clientAthena = boto3.client('athena', region_name=awsRegion) athenaQueryExecResp = clientAthena.start_query_execution( QueryString=self.athenaQuery, QueryExecutionContext={ 'Database': self.athenaDB }, ResultConfiguration={'OutputLocation': self.athenaResultBucket } ) print(

Stream large string to S3 using boto3

天涯浪子 提交于 2020-08-05 05:12:08
问题 I am downloading files from S3, transforming the data inside them, and then creating a new file to upload to S3. The files I am downloading are less than 2GB but because I am enhancing the data, when I go to upload it, it is quite large (200gb+). Currently you could imagine by code is like: files = list_files_in_s3() new_file = open('new_file','w') for file in files: file_data = fetch_object_from_s3(file) str_out = '' for data in file_data: str_out += transform_data(data) new_file.write(str

What is the difference between S3.Client.upload_file() and S3.Client.upload_fileobj()?

末鹿安然 提交于 2020-07-18 10:24:25
问题 According to S3.Client.upload_file and S3.Client.upload_fileobj, upload_fileobj may sound faster. But does anyone know specifics? Should I just upload the file, or should I open the file in binary mode to use upload_fileobj ? In other words, import boto3 s3 = boto3.resource('s3') ### Version 1 s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt') ### Version 2 with open('/tmp/hello.txt', 'rb') as data: s3.upload_fileobj(data, 'mybucket', 'hello.txt') Is version 1 or version 2

How to use python ElasticSearch package with ECS Instance Role instead of passing credentials?

别等时光非礼了梦想. 提交于 2020-07-10 10:29:38
问题 I've built an app that queries ElasticSearch at various times. Now that I'm moving the app to be hosted on a ECS, I want to switch my queries to be based on the Instance Role permissions rather than credentials that I've been passing as environment variables. Based on the docs, if I pass no credentials to Boto3, I ought to get use my Instance Role. But in order to send my query using the ElasticSearch package in python, I have to pass credentials. Is there a way to do this using Instance

not getting all aws instances using python boto3 - problem with Reservation

我与影子孤独终老i 提交于 2020-07-10 10:28:38
问题 I have written a python-boto3 script to get all aws instances list from an account and region. the script is running fine, but not giving all instances. for example ,if n instances are with same Reservation number then getting only one instance under Reservation. please look at the below script , please help me how can I get all aws instances list irrespective of reservation number. rg = 'us-west-2' config = Config( retries = dict( max_attempts = 100 ) ) ec = boto3.client('ec2', config=config

not getting all aws instances using python boto3 - problem with Reservation

蓝咒 提交于 2020-07-10 10:28:31
问题 I have written a python-boto3 script to get all aws instances list from an account and region. the script is running fine, but not giving all instances. for example ,if n instances are with same Reservation number then getting only one instance under Reservation. please look at the below script , please help me how can I get all aws instances list irrespective of reservation number. rg = 'us-west-2' config = Config( retries = dict( max_attempts = 100 ) ) ec = boto3.client('ec2', config=config

Python Boto3 - how to check if s3 file is completely written before process start copying to another bucket

ぐ巨炮叔叔 提交于 2020-07-09 15:07:49
问题 How to make sure that Process A has completely written large file (5+ GB) in AWS S3 Bucket A before Process B starts copying file to AWS S3 Bucket B using boto3? 回答1: If a new object is being created in Amazon S3, it will only appear after the upload is complete. Other processes will not be able to view it until is has finished uploading. Objects cannot be updated in S3. Rather, they are replaced with a new object. So, if an object is in the process of being updated, it will still appear as

Python Boto3 - how to check if s3 file is completely written before process start copying to another bucket

扶醉桌前 提交于 2020-07-09 15:07:29
问题 How to make sure that Process A has completely written large file (5+ GB) in AWS S3 Bucket A before Process B starts copying file to AWS S3 Bucket B using boto3? 回答1: If a new object is being created in Amazon S3, it will only appear after the upload is complete. Other processes will not be able to view it until is has finished uploading. Objects cannot be updated in S3. Rather, they are replaced with a new object. So, if an object is in the process of being updated, it will still appear as

How can an ECS task know in which region is runs?

落花浮王杯 提交于 2020-07-09 14:58:42
问题 I have a python application using boto3 in a task launched by ECS (in a docker container). The boto3 command I use need a region to work properly, but I only know the region at runtime (multi-region application). The idea was then to define the AWS_DEFAULT_REGION environment variable by retrieving the region in the dynamic document provided by Amazon from URI http://169.254.169.254. However, whereas the call works fine from the instance, I cannot access the endpoint from within the task