This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Description: An app that includes a DynamoDB table, a Lambda function that writes to DynamoDB, and a scheduled EventBridge event | |
Resources: | |
LambdaWriteToDynamoDB: | |
# A function that writes to a DynamoDB table on a schedule | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
FunctionName: LambdaWriteToDynamoDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Resources: | |
Function: | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
CodeUri: src/Function | |
Handler: handler.handler | |
Runtime: python3.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transform: AWS::Serverless-2016-10-31 | |
Resources: | |
SourceBucket: | |
Type: AWS::S3::Bucket | |
DestinationBucket: | |
Type: AWS::S3::Bucket | |
Function: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: src/Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transform: AWS::Serverless-2016-10-31 | |
Resources: | |
Function: | |
Type: AWS::Serverless::Function # This resource is a Lambda function | |
Properties: | |
CodeUri: src/Function # Location in your file structure where the function code is saved | |
Handler: index.handler # Your Lambda function handler, or the method in your function code that's called every time your function is invoked | |
Runtime: python3.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GenerateAudioStateMachine: | |
Type: AWS::Serverless::StateMachine | |
Properties: | |
Name: !Sub GenerateAudioStateMachine-${Stage} | |
DefinitionUri: src/generate_audio_state_machine.asl.json | |
DefinitionSubstitutions: | |
TableName: !Ref DynamoDBTable | |
GetWordsForListIdFunction: !Ref GetWordsForListId | |
PronunciationAudioBucket: !Ref PronunciationAudioBucket | |
Policies: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Description: An example deployment for migrating data between DynamoDB tables | |
Resources: | |
ExistingTable: | |
Type: AWS::DynamoDB::Table | |
DeletionPolicy: Retain | |
Properties: | |
TableName: ExportDataTable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import boto3 | |
from datetime import datetime | |
# Import resources using AWS Python SDK (boto3) and specify the DynamoDB table to scan and S3 bucket to write file to | |
# Table and bucket name are passed as environment variables in SAM template | |
s3 = boto3.resource('s3') | |
bucket = s3.Bucket(os.environ['BUCKET_NAME']) | |
table = boto3.resource('dynamodb').Table(os.environ['TABLE_NAME']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
NewerOlder