0% found this document useful (0 votes)
2 views3 pages

Python With Aws Notes

This document provides developer notes on using Python with AWS, specifically focusing on the Boto3 SDK. It covers various functionalities including S3 file upload/download, DynamoDB CRUD operations, Lambda functions, SQS message handling, SNS notifications, reading secrets from Secrets Manager, CloudWatch logs, and IAM role assumption. Each section includes code snippets for basic usage and deployment instructions.

Uploaded by

Harsh Mendapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python With Aws Notes

This document provides developer notes on using Python with AWS, specifically focusing on the Boto3 SDK. It covers various functionalities including S3 file upload/download, DynamoDB CRUD operations, Lambda functions, SQS message handling, SNS notifications, reading secrets from Secrets Manager, CloudWatch logs, and IAM role assumption. Each section includes code snippets for basic usage and deployment instructions.

Uploaded by

Harsh Mendapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

🐍 Python with AWS – Developer Notes

🔹 1. AWS SDK for Python (Boto3)

• Install:

pip install boto3

• Basic Usage:

import boto3
s3 = boto3.client('s3')
s3.upload_file('local_file.txt', 'bucket-name', 'remote_file.txt')

🔹 2. S3 File Upload/Download

s3 = boto3.client('s3')
s3.upload_file('test.png', 'my-bucket', 'images/test.png')
s3.download_file('my-bucket', 'images/test.png', 'downloaded_test.png')

🔹 3. DynamoDB CRUD

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')

# Insert
response = table.put_item(Item={'UserID': '123', 'Name': 'Alice'})

# Read
item = table.get_item(Key={'UserID': '123'})

# Update
table.update_item(
Key={'UserID': '123'},
UpdateExpression='SET Name = :val1',
ExpressionAttributeValues={':val1': 'Bob'}
)

1
# Delete
table.delete_item(Key={'UserID': '123'})

🔹 4. Lambda Function in Python

def lambda_handler(event, context):


return {
'statusCode': 200,
'body': 'Hello from Lambda!'
}

• Deploy via AWS Console or CLI.

🔹 5. SQS – Send/Receive Messages

sqs = boto3.client('sqs')
queue_url = 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue'

# Send
sqs.send_message(QueueUrl=queue_url, MessageBody='Hello from Python')

# Receive
messages = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=1)

🔹 6. SNS – Publish Notification

sns = boto3.client('sns')
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:my-topic',
Message='Hello from Python!',
Subject='Test SNS'
)

2
🔹 7. Read Secrets from AWS Secrets Manager

client = boto3.client('secretsmanager')
secret_value = client.get_secret_value(SecretId='my-secret-id')
print(secret_value['SecretString'])

🔹 8. CloudWatch Logs

logs = boto3.client('logs')
response = logs.create_log_stream(
logGroupName='my-group',
logStreamName='my-stream'
)

🔹 9. IAM Role Assumption

sts = boto3.client('sts')
creds = sts.assume_role(RoleArn='arn:aws:iam::123456789012:role/MyRole',
RoleSessionName='MySession')['Credentials']

Let me know if you'd like project-specific Python AWS examples (e.g., ETL with S3 + Lambda + Glue).

You might also like