|
| 1 | +# Amazon S3 to AWS Lambda to Amazon Transcribe using AWS SAM |
| 2 | + |
| 3 | +This pattern facilitates automatic audio transcription by using the Amazon Transcribe service through a serverless event-driven architecture. When audio files are uploaded to S3, they are automatically transcribed using Amazon Transcribe via a Lambda function invoked by S3 events. |
| 4 | + |
| 5 | +This pattern enables speech-to-text transcription use cases by providing a serverless event-based pipeline that can process audio files uploaded to S3. The pattern uses AWS Lambda to coordinate with the Amazon Transcribe service, making it easy to integrate transcription capabilities into your applications without the need to manage infrastructure or manually initiate transcription jobs. |
| 6 | + |
| 7 | +Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. |
| 12 | +* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured |
| 13 | +* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 14 | +* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed |
| 15 | + |
| 16 | +## Deployment Instructions |
| 17 | + |
| 18 | +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: |
| 19 | + ``` |
| 20 | + git clone https://github.com/aws-samples/serverless-patterns |
| 21 | + ``` |
| 22 | +1. Change directory to the pattern directory: |
| 23 | + ``` |
| 24 | + cd lambda-transcribe-sam-js |
| 25 | + ``` |
| 26 | +1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yaml file: |
| 27 | + ``` |
| 28 | + sam deploy --guided |
| 29 | + ``` |
| 30 | +1. During the prompts: |
| 31 | + * Enter a stack name |
| 32 | + * Enter the desired AWS Region |
| 33 | + * Allow SAM CLI to create IAM roles with the required permissions. |
| 34 | + * Allow TranscribeFunction to operate without authentication. |
| 35 | + After running `sam deploy --guided` mode once and savings arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults. |
| 36 | +
|
| 37 | +2. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing. |
| 38 | +
|
| 39 | +## How it works |
| 40 | +
|
| 41 | +When an object is uploaded to S3: |
| 42 | +
|
| 43 | +2. Lambda function starts a transcription job using Amazon Transcribe |
| 44 | +3. Amazon Transcribe processes the audio file and generates the transcription |
| 45 | +4. The transcription results are stored in the specified S3 bucket |
| 46 | +
|
| 47 | +## Testing |
| 48 | +
|
| 49 | +To test the deployed API endpoint: |
| 50 | +
|
| 51 | +1. Upload an audio file to the created S3 bucket(Note: Bucket name would be {AWS::StackName}-audio-uploads): |
| 52 | +``` |
| 53 | +aws s3 cp audio.mp3 s3://your-bucket-name/ |
| 54 | +``` |
| 55 | +2. Get the S3 URL of the uploaded audio file |
| 56 | +3. You can list all transcription jobs using: |
| 57 | +
|
| 58 | +```bash |
| 59 | +aws transcribe list-transcription-jobs |
| 60 | +``` |
| 61 | +4. You can check the transcription results in the S3 bucket once the job is complete: |
| 62 | + |
| 63 | +```bash |
| 64 | +aws transcribe get-transcription-job --transcription-job-name "job-name-from-response" |
| 65 | +``` |
| 66 | +## Cleanup |
| 67 | + |
| 68 | +1. Delete the audio.mp3 file from the S3 bucket. This is because the bucket must be empty before it can be deleted. |
| 69 | + ```bash |
| 70 | + aws s3 rm "s3://your-bucket-name/audio.mp3" |
| 71 | + ``` |
| 72 | +2. Delete the stack |
| 73 | + ```bash |
| 74 | + sam delete |
| 75 | + ``` |
| 76 | + |
| 77 | +---- |
| 78 | +Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 79 | + |
| 80 | +SPDX-License-Identifier: MIT-0 |
0 commit comments