amazon-web-services

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

unable to fetch record based on a specific key in dynamo db and python

unable to fetch record based on a specific key in dynamo db and python Question: I have a child class where I am trying to fetch the dynamo db data based on a specific key, I tried multiple variations of passing a value to the key but somehow I am getting an error on the …

Total answers: 1

How to get receipt handle from sqs queue response, getting(TypeError 'sqs.Message' object is not subscriptable

How to get receipt handle from sqs queue response, getting(TypeError 'sqs.Message' object is not subscriptable Question: I have one queue I’m sending some message in that and want to get receipt handle from output response. messages = queue.receive_messages() print(messages) I am receiving this type of response: [sqs.Message(queue_url=’someurl’, receipt_handle=’abcd’)] Now I want to extract only receipt …

Total answers: 1

Get filename from S3 bucket path

Get filename from S3 bucket path Question: I am getting the last modified file from S3 bucket using the below code: import boto3 import urllib.parse import json import botocore.session as bc import time from time import mktime from datetime import datetime print(‘Loading function’) def lambda_handler(event, context): s3_client = boto3.client("s3") list_of_s3_objs = s3_client.list_objects_v2(Bucket="mybucket", Prefix="folder/sub/") # Returns …

Total answers: 2

AccessDenied when calling Boto3 assume_role from EC2 even with service principal

AccessDenied when calling Boto3 assume_role from EC2 even with service principal Question: I’m running into an issue when trying to have a Python script running on an EC2 instance assume a role to perform S3 tasks. Here’s what I have done. Created a IAM role with AmazonS3FullAccess permissions and got the following ARN: arn:aws:iam::<account_number>:role/<role_name> The …

Total answers: 1

Return data from Python's Redshift procedure call

Return data from Python's Redshift procedure call Question: redshift_connector is defined to be aligned with https://peps.python.org/pep-0249/#id24 but I can’t, after calling procedure, retrieve data into a dataframe. Instead I’m getting ‘mycursor’ value. How to overcome this? fetch*() methods don’t allow passing argument that will allow getting into data in mycursor. I also tried RECORDS type …

Total answers: 2

boto3 get_query_runtime_statistics sometimes not returning "rows" data

boto3 get_query_runtime_statistics sometimes not returning "rows" data Question: I have a lambda that attempts to find out whether a previously executed athena query has returned any rows or not. To do so I am using the boto3 function get_query_runtime_statistics and then extracting the "Rows" data: response = athena_client.get_query_runtime_statistics(QueryExecutionId=query_id) row_count = response["QueryRuntimeStatistics"]["Rows"]["OutputRows"] However, in a previous …

Total answers: 2

How to populate an AWS Timestream DB?

How to populate an AWS Timestream DB? Question: I am trying to use AWS Timestream to store data with timesteamp (in python using boto3). The data I need to store corresponds to prices over time of different tokens. Each record has 3 field: token_address, timestamp, price. I have around 100 M records (with timestamps from …

Total answers: 1

how to Read .Sql file stored in S3 containing multiple SQL statements

how to Read .Sql file stored in S3 containing multiple SQL statements Question: I have a .sql file stored in S3 location in AWS which contains multiple SQL statements separated by semi colon as below: Query1; _______________ Query2; _______________ Query3; tried using 2 methods in AWS Glue job to read this S3 .sql file but …

Total answers: 1

AWS ECS environment variable not available [Python]

AWS ECS environment variable not available [Python] Question: I am using AWS ECS with a Python Framework and in my task definition i have the option to add environment variables that will be available to the service(cluster). Here is where i added the env variables: When i then try to print all the env variables …

Total answers: 1