Posts

Showing posts from February, 2026

python code to access s3 bucket from different account - Using Separate Boto3 Sessions/Profiles

This method is typically used to copy objects between buckets without saving them locally.     import boto3 import io # Source Account Credentials (can be loaded from .env file or config) SOURCE_ACCESS_KEY = '...' SOURCE_SECRET_KEY = '...' SOURCE_BUCKET = 'my-source-bucket' # Destination Account Credentials DESTINATION_ACCESS_KEY = '...' DESTINATION_SECRET_KEY = '...' DESTINATION_BUCKET = 'their-destination-bucket' OBJECT_KEY = 'path/to/object.txt' # 1. Create a client for the source account source_client = boto3.client(     's3',     aws_access_key_id=SOURCE_ACCESS_KEY,     aws_secret_access_key=SOURCE_SECRET_KEY ) # 2. Get the object data as a stream (file-like object) source_object = source_client.get_object(Bucket=SOURCE_BUCKET, Key=OBJECT_KEY) object_body = source_object['Body'] # 3. Create a client for the destination account destination_client = boto3.client(     's3',     aws_access_key_id=DESTINATI...

Iterator and Generator in Js

  Difference between for-in and for-of let object1 = {        let arr = [1,2,3,4]; for (let key in arr) { //key = 0,1,2,3 } for (let key in object1) { //key = 0,1,2,3 } For-in can do both array and object For-of can do object, it does only array What is iterable? enumerable as false makes non iterable getOwnPropertyD Symbol is datatype added in typescript , if we add a  Generator yeild To make an object, we can use the define property method itself to make enumerable as true instead of going for generator/ extending object with symbol.iterator right? What is advantage and when we go for generator/symbol iterator?

python code to access s3 bucket from different account - Assuming an IAM Role

 import boto3 # 1. Configuration for the destination account's role DESTINATION_ACCOUNT_ID = '123456789012' # Replace with the destination account ID DESTINATION_ROLE_NAME = 'CrossAccountUploadRole' # Replace with the role name ROLE_ARN = f"arn:aws:iam::{DESTINATION_ACCOUNT_ID}:role/{DESTINATION_ROLE_NAME}" BUCKET_NAME = 'their-destination-bucket' # Replace with the destination bucket name FILE_NAME = 'local_file.txt' OBJECT_KEY = 'uploads/file.txt' # The key (path) in the S3 bucket # 2. Assume the role sts_client = boto3.client('sts') assumed_role_object = sts_client.assume_role(     RoleArn=ROLE_ARN,     RoleSessionName="CrossAccountS3UploadSession" ) credentials = assumed_role_object['Credentials'] # 3. Create a new S3 client using the temporary credentials session = boto3.Session(     aws_access_key_id=credentials['AccessKeyId'],     aws_secret_access_key=credentials['SecretAccessKey'], ...