|
| 1 | +# Subtitle generation with AWS Lambda and Amazon Transcribe |
| 2 | + |
| 3 | +Using this sample pattern, users can securely upload videos to an Amazon S3 bucket by requesting a pre-signed URL through Amazon API Gateway. This URL allows secure and temporary access for uploading files directly to S3. |
| 4 | + |
| 5 | +Once a video file is uploaded, an S3 event invokes another Lambda function to start the Transcribe job using the StartTranscriptionJob API. Once the transcription is completed, the generated subtitles will be stored in the output S3 bucket. |
| 6 | + |
| 7 | +Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-lambda-transcribe |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +* [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. |
| 14 | +* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured |
| 15 | +* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 16 | +* [Terraform](https://learn.hashicorp.cxom/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed |
| 17 | + |
| 18 | +## Deployment Instructions |
| 19 | + |
| 20 | +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: |
| 21 | + ``` |
| 22 | + git clone https://github.com/aws-samples/serverless-patterns |
| 23 | + ``` |
| 24 | +1. Change directory to the pattern directory: |
| 25 | + ``` |
| 26 | + cd apigw-lambda-transcribe |
| 27 | + ``` |
| 28 | +1. From the command line, initialize terraform to downloads and installs the providers defined in the configuration: |
| 29 | + ``` |
| 30 | + terraform init |
| 31 | + ``` |
| 32 | +1. From the command line, apply the configuration in the main.tf file: |
| 33 | + ``` |
| 34 | + terraform apply |
| 35 | + ``` |
| 36 | +1. During the prompts |
| 37 | + ``` |
| 38 | + #var.prefix |
| 39 | + - Enter a value: {enter any prefix to associate with resources} |
| 40 | +
|
| 41 | + #var.region |
| 42 | + - Enter a value: {enter the region for deployment} |
| 43 | + ``` |
| 44 | + |
| 45 | +## Testing |
| 46 | +
|
| 47 | +1. Make a POST request to the API using the following cURL command: |
| 48 | +
|
| 49 | + ``` |
| 50 | + curl --location 'API_ENDPOINT' --header 'Content-Type: application/json' --data '{"object_name": "video.mp4", "content_type": "video/mp4"}' |
| 51 | + ``` |
| 52 | +
|
| 53 | + Note: Replace `API_ENDPOINT` with the generated `api_endpoint` from Terraform (refer to the Terraform Outputs section) `object_name` with your desired name for the S3 object and `content_type` with the content type of the video, for ex, mp4. |
| 54 | +
|
| 55 | +1. Get the pre-signed URL from the previous step and use the following cURL command to upload the object in S3: |
| 56 | +
|
| 57 | + ``` |
| 58 | + curl -v --location -T "video.mp4" 'PRESIGNED_URL' --header 'Content-Type: video/mp4' |
| 59 | + ``` |
| 60 | +
|
| 61 | + Note: Replace `PRESIGNED_URL` with pre-signed URL generated in the previous step. `Content-Type` should match the content type used to generate the pre-signed URL in the previous step. |
| 62 | +
|
| 63 | + Once this command is run successfully and the object is uploaded, HTTP 200 OK should be seen. You can also check the S3 bucket to see if the object is uploaded correctly. |
| 64 | +
|
| 65 | +1. Once the object is uploaded successfully, the `process_s3_event` Lambda function is invoked. Lambda function will then invoke the `StartTranscriptionJob` API and Amazon Transcribe will upload the transcribed output to the output S3 bucket (Refer to the Terraform Outputs section under `output_bucket_name`). |
| 66 | +
|
| 67 | +## Cleanup |
| 68 | + |
| 69 | +1. Delete the Transcription jobs: |
| 70 | + Go to Transcribe > Transcription jobs > Select your transcription jobs and choose Delete |
| 71 | +
|
| 72 | +1. Change directory to the pattern directory: |
| 73 | + ``` |
| 74 | + cd serverless-patterns/apigw-lambda-transcribe |
| 75 | + ``` |
| 76 | +
|
| 77 | +1. Delete all created resources |
| 78 | + ``` |
| 79 | + terraform destroy |
| 80 | + ``` |
| 81 | + |
| 82 | +1. During the prompts: |
| 83 | + ``` |
| 84 | + Enter all details as entered during creation. |
| 85 | + ``` |
| 86 | +
|
| 87 | +1. Confirm all created resources has been deleted |
| 88 | + ``` |
| 89 | + terraform show |
| 90 | + ``` |
| 91 | +---- |
| 92 | +Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 93 | +
|
| 94 | +SPDX-License-Identifier: MIT-0 |
0 commit comments