DEV Community

Cover image for Video Generation using BedRock [Part 1] Amazon Nova Canvas, Lambda and S3
3 1 1

Video Generation using BedRock [Part 1] Amazon Nova Canvas, Lambda and S3

🌟 Hello! I’m AndrĆ©, a Staff Software Engineer and proud member of the AWS Community Builders program. With 9 AWS certifications earned along my journey, I’m constantly pushing the boundaries of what’s possible in the cloud. I’m passionate about designing scalable architectures, experimenting with emerging technologies like Generative AI, and giving back to the tech community by sharing what I learn. Excited to connect with fellow builders and innovators as we shape the future of cloud computing! šŸš€

Introduction

In this article, we’ll explore how you can build your own AI-powered video generation workflow using Amazon Bedrock, AWS Lambda, AWS Cloudwatch and Amazon S3. We'll leverage Amazon Nova Reels as the foundation model to generate custom videos based on text prompts provided by users.

Initial Approach adopted

The diagram shows a user submitting a text prompt to an AWS Lambda function labeled

This solution follows an asynchronous architecture: the first Lambda function receives the prompt and triggers the video generation process in Amazon Bedrock. Once the video is created and saved automatically in an S3 bucket, an S3 Event Notification triggers a second Lambda function that generates a pre-signed URL on AWS Cloudwatch for enabling access to the video.

Target Audience

This guide is ideal for AWS Community Builders, IT professionals, and Generative AI enthusiasts who want to integrate AI-driven video generation into real-world serverless applications.

Bedrock Prerequisites

Accessing Amazon Nova Foundation Model via Amazon Bedrock
Before starting your project, make sure you complete the following steps:

AWS Account Setup:

  • Have an active AWS Account with billing enabled.
  • Ensure your IAM user or role has the necessary Bedrock service permissions, such as:

bedrock:InvokeModel
bedrock:ListFoundationModels

Step 1: Enable Amazon Bedrock in Your AWS Account:

  • Log in to the AWS Management Console.
  • Navigate to the Amazon Bedrock service.
  • Make sure you are in a supported AWS region, like us-east-1.

Console AWS

Step 2: Request Access to Amazon Nova Foundation Model:

  • In the Bedrock Console, go to ā€œModel accessā€.
  • Under ā€œManage model accessā€, locate Amazon Nova Foundation Model.
    Presentation page Bed Rock

  • Click ā€œRequest accessā€ for the Nova model if you don’t already have it.

  • Wait for AWS approval. This process can take from a few minutes to several hours, depending on your AWS account and region.

List of models

Step 3: Gather Model API Details:
Go to the ā€œFoundation modelsā€ section in the Bedrock Console (left-hand menu).

List of models params


First lambda - Start video creation process

Code explaned below

Importing Required Libraries and Initializing Parameters

import json          # For returning API responses in JSON format
import boto3          # AWS SDK for Python (to call Bedrock)
import random         # To generate a random seed for output variability

def lambda_handler(event, context):
    # Initialize Bedrock client in the desired AWS region
    bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")

    # Get the input prompt from the event (or use default)
    prompt = event.get("prompt", "Sample video")

    # Generate a random seed to ensure unique output per request
    seed = random.randint(0, 2_147_483_646)
Enter fullscreen mode Exit fullscreen mode

Triggering Asynchronous Video Generation

response = bedrock.start_async_invoke(
    modelId="amazon.nova-reel-v1:0",
    modelInput={
        "taskType": "TEXT_VIDEO",
        "textToVideoParams": {"text": prompt},
        "videoGenerationConfig": {
            "fps": 24,
            "durationSeconds": 6,
            "dimension": "1280x720",
            "seed": seed
        }
    },
    outputDataConfig={"s3OutputDataConfig": {"BUCKETNAME/outputs/"}}
)
Enter fullscreen mode Exit fullscreen mode

This is the heart of the Lambda function. We are calling the Bedrock API's start_async_invoke method, which is used for models that run *asynchronously *(like video generation with Nova Reels).

    return {
        "statusCode": 202,
        "body": json.dumps({"invocationArn": response["invocationArn"]}),
    }
Enter fullscreen mode Exit fullscreen mode

Finally, the Lambda returns a 202 Accepted HTTP status code, along with the invocationArn, which acts as the Job ID for tracking the status of the asynchronous generation process.


Second lambda - Post processing event

Code explaned below

import boto3
import json

s3 = boto3.client("s3")  # S3 client for generating pre-signed URLs

def lambda_handler(event, context):
    print(json.dumps(event))  # Log the incoming S3 event payload

    for record in event['Records']:
        bucket = record['s3']['bucket']['name']  # Bucket name where the video was saved
        key = record['s3']['object']['key']      # Object key (file path) of the uploaded video

        # Generate a pre-signed URL valid for 1 hour
        presigned_url = s3.generate_presigned_url(
            ClientMethod='get_object',
            Params={'Bucket': bucket, 'Key': key},
            ExpiresIn=3600
        )

        print(f"Video URL: {presigned_url}")  # Log the generated link (you can replace this with SNS, DynamoDB, etc.)

    return {
        "statusCode": 200,
        "body": json.dumps({"message": "Processed"})
    }
Enter fullscreen mode Exit fullscreen mode

Calling the first lambda

Input text to test

Successful message

Getting the video pre-signedUrl after de S3 event calls the second lambda

Seeing the URL

Seeing the video

AI Generated video from your application

Seeing the video


And that’s a wrap!

Thank you for taking the time to read through this guide. I hope it brought you clarity and practical knowledge to help you on your cloud and AI journey. I’m passionate about making technical topics more accessible, and there’s plenty more content coming soon. Stay curious, keep experimenting, and let’s continue building great things together!

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

šŸ‘‹ Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay