boto

AWS Boto3 sts get_caller_identity – catching exceptions if credentials are invalid

AWS Boto3 sts get_caller_identity – catching exceptions if credentials are invalid Question: With a Python app, using Boto3 v1.26.59 (and botocore of same version) about the first thing done is to try to get the username of the user. We have Identity Center (SSO) users. With aged credentials (token), two exceptions are thrown and I …

Total answers: 1

AttributeError: 'dict' object has no attribute 'Instance' python

AttributeError: 'dict' object has no attribute 'Instance' python Question: i am trying to start the EC2 Instance with PrivateIP where i provide as argument "PrivateIP" and below code will describe the ec2 and get InstanceId. Once InstanceId received, it starts the EC2 instance def status_ec2_instance(instanceIds_list, region_Name): ec2 = boto3.resource(‘ec2’, region_name=region_Name) ec2_client = boto3.client(‘ec2’, region_name=region_Name) print(instanceIds_list) …

Total answers: 1

How to use S3 Select with tab separated csv files

How to use S3 Select with tab separated csv files Question: I’m using this script to query data from a CSV file that’s saved on an AWS S3 Bucket. It works well with CSV files that were originally saved in Comma Separated format but I have a lot of data saved with tab delimiter (Sep=’t’) …

Total answers: 2

SNS mocking with moto is not working correctly

SNS mocking with moto is not working correctly Question: In my unit test: def test_my_function_that_publishes_to_sns(): conn = boto3.client("sns", region_name="us-east-1") mock_topic = conn.create_topic(Name="mock-topic") topic_arn = mock_topic.get("TopicArn") os.environ["SNS_TOPIC"] = topic_arn # call my_function my_module.my_method() The the function being tested # inside my_module, my_function… sns_client.publish( TopicArn=os.environ["SNS_TOPIC"], Message="my message", ) I get the error: botocore.errorfactory.NotFoundException: An error occurred (NotFound) …

Total answers: 3

How to identify disabled regions in AWS?

How to identify disabled regions in AWS? Question: AWS regularly add new regions. While “old” regions are enabled by default in every AWS account, new regions are disabled by default 1. I’m trying to scan a particular resource in all available regions using the following Python (pseudo)code: regions = boto3_session.get_available_regions(‘rds’) for region in regions: boto_rds_client …

Total answers: 3

How to use Boto to self-terminate instance its running on?

How to use Boto to self-terminate instance its running on? Question: I need to terminate an instance from an AutoScalingGroup as the policies ASG has are leaving the scaled out instances running longer than desired. I need to terminate said instance after its done running a python process. The code already uses Boto to access …

Total answers: 2

Read ZIP files from S3 without downloading the entire file

Read ZIP files from S3 without downloading the entire file Question: We have ZIP files that are 5-10GB in size. The typical ZIP file has 5-10 internal files, each 1-5 GB in size uncompressed. I have a nice set of Python tools for reading these files. Basically, I can open a filename and if there …

Total answers: 4

Amazon mws access denied for european marketplace

Amazon mws access denied for european marketplace Question: I’m trying to pull competetive prices from amazon mws using boto. When I try to do it for US marketplace it works perfectly fine, bun when I try to do it using European endpoint it returns boto.mws.response.AccessDenied: AccessDenied: Unauthorized Access denied Here is the code Im using …

Total answers: 1

How to upload a file to S3 and make it public using boto3?

How to upload a file to S3 and make it public using boto3? Question: I am able to upload an image file using: s3 = session.resource(‘s3’) bucket = s3.Bucket(S3_BUCKET) bucket.upload_file(file, key) However, I want to make the file public too. I tried looking up for some functions to set ACL for the file but seems …

Total answers: 5

How do I upload a CSV file in myBucket and Read File in S3 AWS using Python

How do I upload a CSV file in myBucket and Read File in S3 AWS using Python Question: How do I upload a CSV file from my local machine to my AWS S3 bucket and read that CSV file? bucket = aws_connection.get_bucket(‘mybucket’) #with this i am able to create bucket folders = bucket.list(“”,”/”) for folder …

Total answers: 1