boto3

AWS Lambda Python Boto3 – Item count dynamodb table

AWS Lambda Python Boto3 – Item count dynamodb table Question: I am trying to count the total number of items in the Dynamobd table. Boto3 documenation says item_count attribute. (integer) — The number of items in the specified table. DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this …

Total answers: 1

How to compress image and then upload it to AWS S3 bucket using FastAPI?

How to compress image and then upload it to AWS S3 bucket using FastAPI? Question: Here is my code for uploading the image to AWS S3: @app.post("/post_ads") async def create_upload_files(files: list[UploadFile] = File(description="Multiple files as UploadFile")): main_image_list = [] for file in files: s3 = boto3.resource( ‘s3’, aws_access_key_id = aws_access_key_id, aws_secret_access_key = aws_secret_access_key ) bucket …

Total answers: 2

How do I download a folder from AWS S3 with CloudPathLib from a public bucket?

How do I download a folder from AWS S3 with CloudPathLib from a public bucket? Question: I’m trying to download a folder from a public AWS S3 bucket using the Python library cloudpathlib. My code looks like this: from cloudpathlib import CloudPath path = r"C:somepathtofolder" url = "s3://some-example-bucket/folder/" cloud_path = CloudPath(url) cloud_path.download_to(path) Really straight forward. …

Total answers: 3

How to get debug logs from boto3 in a local script?

How to get debug logs from boto3 in a local script? Question: I have a local script that lists buckets: import boto3 s3_client = boto3.client(‘s3’) for bucket in s3_client.list_buckets()["Buckets"]: print(bucket[‘Name’]) when I execute it locally, it does just that. Now if I execute this code as a lambda on AWS and set the log level …

Total answers: 2

How can I get the AMI Id through the AMI name with boto3?

How can I get the AMI Id through the AMI name with boto3? Question: I’m trying to automate the creation of an autoscaling group Cloudformation Template using an EC2 instance already deployed and running so, for making an exact copy I need to have the AMI of the current instance. In order to get the …

Total answers: 2

AWS Lambda Python boto3 EC2 instances starting – "errorType": "UnboundLocalError",

AWS Lambda Python boto3 EC2 instances starting – "errorType": "UnboundLocalError", Question: My intent of this program is to start ec2 instances based on the event. It doesn’t like the following 2 lines of code for each_scheduled_instance in ec2_console_resource.instances.all(): each_scheduled_instance.start() This is the program. { "errorMessage": "local variable ‘each_scheduled_instance’ referenced before assignment", "errorType": "UnboundLocalError", "requestId": "3054209f-5cf7-429e-bcc7-7109a3b28a29", …

Total answers: 1

Unable to upload file to AWS S3 using python boto3 and upload_fileobj

Unable to upload file to AWS S3 using python boto3 and upload_fileobj Question: I am trying to get a webp image, convert it to jpg and upload it to aws S3 without saving the file to disk (using io.BytesIO and boto3 upload_fileobj) , but with no success. The funny thing is that it works fine …

Total answers: 1

How to filter Amazon EBS snapshots by image (AMI) ID?

How to filter Amazon EBS snapshots by image (AMI) ID? Question: I would like to get all Amazon EBS snapshots that are associated with a certain AMI (image). Is that possible? I can filter by tag ie. previous_snapshots = ec2.describe_snapshots(Filters=[{‘Name’: ‘tag:SnapAndDelete’, ‘Values’: [‘True’]}])[‘Snapshots’] for snapshot in previous_snapshots: print(‘Deleting snapshot {}’.format(snapshot[‘SnapshotId’])) ec2.delete_snapshot(SnapshotId=snapshot[‘SnapshotId’]) Is there a filter …

Total answers: 1

How to return a PDF file from in-memory buffer using FastAPI?

How to return a PDF file from in-memory buffer using FastAPI? Question: I want to get a PDF file from s3 and then return it to the frontend from FastAPI backend. This is my code: @router.post("/pdf_document") def get_pdf(document : PDFRequest) : s3 = boto3.client(‘s3’) file=document.name f=io.BytesIO() s3.download_fileobj(‘adm2yearsdatapdf’, file,f) return StreamingResponse(f, media_type="application/pdf") This API returns 200 …

Total answers: 1