Posts

Showing posts with the label Python

How to Use Amazon Polly to Convert Text to Speech and Store MP3 Files in S3

You have a content pipeline — articles, blog posts, documentation — and you want to ship an audio version without standing up a separate TTS infrastructure. Amazon Polly lets you call a single API, get back an MP3 stream, and pipe it directly to S3. The tricky part is understanding which voice options are available for non-English languages like Korean, and how the neural vs. standard engine selection affects both quality and cost. TL;DR: Amazon Polly Text-to-Speech Pipeline Step Action Key Decision 1 Choose engine (Neural vs. Standard) Neural sounds better; not all voices support it 2 Select voice ID for target language Korean: Seoyeon (Neural supported) 3 Call SynthesizeSpeech or StartSpeechSynthesisTask Short text → SynthesizeSpeech; long text → async task 4 Write audio stream to S3 Use PutObject or let Polly write directly via async task How Amazon Polly Text-to-Speech Works Polly exposes two s...

How to Use Amazon Rekognition to Detect Objects in an Image from Lambda

You've got an S3 bucket filling up with user-uploaded photos, and someone asks: 'Can we auto-tag these with what's actually in them?' That's exactly the problem Amazon Rekognition's DetectLabels API solves — and wiring it to a Lambda function triggered by S3 uploads is the most common production pattern for this use case. TL;DR: Amazon Rekognition DetectLabels via Lambda Step What Happens 1. Image uploaded to S3 S3 event notification triggers Lambda 2. Lambda invokes DetectLabels Passes S3 bucket + object key to Rekognition 3. Rekognition returns labels JSON array with label names and confidence scores 4. Lambda stores results Write tags to DynamoDB, S3 metadata, or downstream system How Amazon Rekognition DetectLabels Works DetectLabels analyzes an image and returns a list of labels — objects, scenes, concepts, and activities detected in the image — each with a confidence ...

How to Create a Lambda Layer for Shared Python Libraries

You have three Lambda functions, each packaging the same requests library independently. Every deploy zips the same 15 MB, every cold start loads the same bytes, and when you need to pin a new version you touch three functions instead of one. Lambda Layers exist precisely to break this pattern — one versioned artifact, attached to as many functions as you need. TL;DR: Lambda Layer Creation at a Glance Step What Happens Key Detail 1. Build package locally pip installs into a directory matching the Lambda runtime path Must be python/ subdirectory 2. Zip the directory Creates the layer artifact Zip must contain python/ at root 3. Publish layer version Lambda stores the artifact and returns a versioned ARN Each publish creates a new immutable version 4. Attach to functions Function config references the layer ARN Up to 5 layers per function; combined unzipped size limit applies How Lambda Layers Work...

How to Connect RDS PostgreSQL from Lambda Using Python and Parameter Store

You've got a Python Lambda that needs to query a PostgreSQL RDS instance — straightforward on paper, but the moment you try to import psycopg2 , Lambda throws a module-not-found error, and you realize the database password sitting in an environment variable is a security incident waiting to happen. This post walks through building a working psycopg2 Lambda layer, wiring up the VPC networking, and pulling credentials securely from AWS Systems Manager Parameter Store. TL;DR: Lambda to RDS PostgreSQL Connection Problem Solution psycopg2 not available in Lambda runtime Build a Lambda Layer with the compiled binary using Docker Database password in plaintext env var Store as SecureString in SSM Parameter Store, fetch at runtime Lambda cannot reach RDS Deploy Lambda in the same VPC, configure Security Group rules Cold start latency from SSM calls Cache the parameter value in the Lambda execution context ...

What is AWS CDK and How is it Different from CloudFormation

If you've spent any time manually writing CloudFormation YAML, you've probably felt the friction — hundreds of lines of declarative markup to express what should be a straightforward pattern. AWS CDK lets you define the same infrastructure using Python classes, loops, and conditionals, then synthesizes it into CloudFormation under the hood. Understanding where CDK ends and CloudFormation begins is what separates engineers who use CDK effectively from those who fight it. TL;DR: AWS CDK vs CloudFormation Dimension AWS CDK CloudFormation Authoring language Python, TypeScript, Java, Go, C# YAML / JSON Abstraction level High-level constructs + raw escape hatches Raw resource declarations Reuse mechanism Python classes, pip packages, Construct Hub Nested stacks, macros Deployment engine CloudFormation (synthesized template) CloudFormation directly Diff / preview cdk diff before deploy Change sets ...