|
| 1 | +# Amazon API Gateway to AWS Lambda to Amazon Transcribe using AWS SAM |
| 2 | + |
| 3 | +This pattern facilitates audio transcription by using Amazon Transcribe service through a serverless API endpoint. When audio files are uploaded to S3, they can be transcribed using Amazon Transcribe via an API Gateway endpoint backed by Lambda. |
| 4 | + |
| 5 | +This pattern enables speech-to-text transcription use cases by providing a serverless API endpoint that can process audio files stored in S3. The pattern uses AWS Lambda to coordinate with Amazon Transcribe service, making it easy to integrate transcription capabilities into your applications. |
| 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 apigw-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 | +
|
| 35 | + Once you have run `sam deploy --guided` mode once and saved 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 | +The pattern creates an API Gateway endpoint that accepts POST requests with JSON payloads containing an S3 URL of an audio file. When a request is received: |
| 42 | +
|
| 43 | +1. API Gateway forwards the request to AWS Lambda |
| 44 | +2. Lambda function starts a transcription job using Amazon Transcribe |
| 45 | +3. Amazon Transcribe processes the audio file and generates the transcription |
| 46 | +4. The transcription results are stored in the specified S3 bucket |
| 47 | +
|
| 48 | +## Testing |
| 49 | +
|
| 50 | +To test the deployed API endpoint: |
| 51 | +
|
| 52 | +1. Upload an audio file to the created S3 bucket: |
| 53 | +``` |
| 54 | +aws s3 cp audio.mp3 s3://your-bucket-name/ |
| 55 | +``` |
| 56 | +2. Get the S3 URL of the uploaded audio file |
| 57 | +3. Make a POST request to the API Gateway endpoint with the following JSON payload: |
| 58 | +
|
| 59 | +```bash |
| 60 | +curl -X POST https://your-api-endpoint/Prod/transcribe \ |
| 61 | + -H "Content-Type: application/json" \ |
| 62 | + -d '{"audio_url": "s3://your-bucket-name/audio.mp3"}' |
| 63 | +``` |
| 64 | +4. The API will return a response with the transcription job name and status |
| 65 | +```json |
| 66 | +{ |
| 67 | + "job_name": "transcribe-12345678-1234-5678-1234-567812345678", |
| 68 | + "status": "IN_PROGRESS" |
| 69 | +} |
| 70 | +``` |
| 71 | +5. You can check the transcription results in the S3 bucket once the job is complete: |
| 72 | + |
| 73 | +```bash |
| 74 | +aws transcribe get-transcription-job --transcription-job-name "job-name-from-response" |
| 75 | +``` |
| 76 | +## Cleanup |
| 77 | + |
| 78 | +1. Delete the stack |
| 79 | + ```bash |
| 80 | + sam delete |
| 81 | + ``` |
| 82 | + |
| 83 | +---- |
| 84 | +Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 85 | + |
| 86 | +SPDX-License-Identifier: MIT-0 |
0 commit comments