Skip to content

Instantly share code, notes, and snippets.

em-shea /
Last active May 3, 2023 17:37
Get words for a given list ID function
# Given a list id, retrieve an array with word ids and simplified characters for that list
# This function is part of a state machine that generates pronunciation audio files for a given list
import list_word_service
def lambda_handler(event, context):
list_id = event['list_id']
last_word_token = event['last_word_token']
# Call to list_word_service, a shared service in the application
# for querying DynamoDB for words by list ID
em-shea / generate_audio_state_machine.yaml
Last active May 3, 2023 18:13
SAM definition for audio generation workflow
View generate_audio_state_machine.yaml
Type: AWS::Serverless::StateMachine
Name: !Sub GenerateAudioStateMachine-${Stage}
DefinitionUri: src/generate_audio_state_machine.asl.json
TableName: !Ref DynamoDBTable
GetWordsForListIdFunction: !Ref GetWordsForListId
PronunciationAudioBucket: !Ref PronunciationAudioBucket
em-shea / audio-workflow-asl-definition.json
Created May 3, 2023 03:27
ASL definition for audio generation workflow
View audio-workflow-asl-definition.json
"Comment": "Generates and save audio files for a given list ID.",
"StartAt": "Get word list",
"States": {
"Get word list": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload": {
View dynamodb_migration_sam.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An example deployment for migrating data between DynamoDB tables
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
TableName: ExportDataTable
em-shea / daily-vocab-app-table-design.json
Created January 29, 2022 14:57
Example of DynamoDB single table design for a daily vocabapp (NoSQL Workbench json)
View daily-vocab-app-table-design.json
"ModelName": "full-table-design",
"ModelMetadata": {
"Author": "",
"DateCreated": "Jun 04, 2021, 05:33 PM",
"DateLastModified": "Jun 16, 2021, 11:01 PM",
"Description": "",
"AWSService": "Amazon DynamoDB",
"Version": "3.0"
em-shea /
Last active July 3, 2022 16:25
Example script to import DynamoDB table data
import json
import boto3
# Specify your existing (export) and new (import) table names and the region your tables are in
export_table_name = "ExportDataTable"
import_table_name = "ImportDataTable"
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table(import_table_name)
def import_table_data():
em-shea /
Last active July 3, 2022 16:17
Example script to export DynamoDB table data
import json
import boto3
# Specify your table name and the region your table is in
export_table_name = "ExportDataTable"
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table(export_table_name)
def export_table_data():
print(f"Exporting data from {export_table_name}")
em-shea /
Created January 16, 2022 19:25
An example of a user service querying DynamoDB and formatting the response
import os
import boto3
import datetime
from typing import List, Dict
from dataclasses import dataclass
from boto3.dynamodb.conditions import Key
class Subscription:
list_name: str
import os
import boto3
# Explicitly specifying where the default AWS region is found
# (as an environment variable) to be able to mock it in the test
s3_client = boto3.client('s3', region_name=os.environ['AWS_REGION'])
translate_client = boto3.client('translate', region_name=os.environ['AWS_REGION'])
def lambda_handler(event, context):
# Mock S3 new file uploaded event
def s3_upload_event(self, file_name):
return {