AWS Lambda code in Python 3.13 using Amazon Nova Reels v1.1

0

I am trying to get my AWS Lambda function to call amazon Nova Reels v1.1 in order to get an Ai video made, and sent to my novabucket S3 bucket.

2 Answers
1
Accepted Answer

Hello.

As of April 2025, Lambda can be used with up to Python 3.13.
The contents of the AWS re:Post Agent's automatic responses seem to be learned from slightly old data.
Although it is not Lambda, the following document provides sample Python code.
If you run this code as a function under "def lambda_handler(event, context):", you should be able to run Bedrock's Nova Reels v1 from Lambda and place the videos created on S3.
https://docs.aws.amazon.com/nova/latest/userguide/video-gen-code-examples.html

profile picture
EXPERT
answered a month ago
profile pictureAWS
EXPERT
reviewed a month ago
  • I tried to make the code described in the documentation run on Lambda as follows. I tried running it in the us-east-1 region and the video was saved to S3 without any problems.

    import json
    import boto3
    
    # Create the Bedrock Runtime client.
    bedrock_runtime = boto3.client("bedrock-runtime")
    
    def lambda_handler(event, context):
        model_input = {
            "taskType": "TEXT_VIDEO",
            "textToVideoParams": {
                "text": "Closeup of a large seashell in the sand, gentle waves flow around the shell. Camera zoom in."
            },
            "videoGenerationConfig": {
                "durationSeconds": 6,
                "fps": 24,
                "dimension": "1280x720",
                "seed": 0,  # Change the seed to get a different result
            },
        }
        try:
            # Start the asynchronous video generation job.
            invocation = bedrock_runtime.start_async_invoke(
                modelId="amazon.nova-reel-v1:1",
                modelInput=model_input,
                outputDataConfig={
                    "s3OutputDataConfig": {
                        "s3Uri": "s3://<your-bucket-name>"
                    }
                }
            )
    
            # Print the response JSON.
            print("Response:")
            print(json.dumps(invocation, indent=2, default=str))
    
        except Exception as e:
            # Implement error handling here.
            message = e.response["Error"]["Message"]
            print(f"Error: {message}")
    
  • Amazing! Thank you so much!!!!

-1

I'm sorry, but there are a few issues with the scenario you've described:

  1. Python 3.13 does not exist yet. The latest stable version of Python is 3.11, with 3.12 in development.

  2. There is no "Amazon Nova Reels v1.1". The correct name is "Amazon Nova Reel" (singular), and its current version is v1:0.

  3. AWS Lambda doesn't directly call Nova Reel. Instead, you would use the Amazon Bedrock runtime client to interact with Nova Reel.

To create an AI-generated video using Amazon Nova Reel from an AWS Lambda function, you would need to:

  1. Use a supported Python version for Lambda (e.g., Python 3.8, 3.9, 3.10, or 3.11).

  2. Install the boto3 library in your Lambda function's deployment package.

  3. Use the bedrock-runtime client to start an asynchronous invocation of the Nova Reel model.

  4. Configure the S3 output location in your request to Nova Reel.

  5. Poll for job completion and retrieve the video from S3 once it's done.

Here's a basic outline of how your Lambda function might look:

import boto3
import json
import time

def lambda_handler(event, context):
    bedrock_runtime = boto3.client('bedrock-runtime')
    
    prompt = "Your text prompt for video generation"
    output_s3_uri = "s3://your-novabucket/output/"
    
    model_input = {
        "taskType": "TEXT_VIDEO",
        "textToVideoParams": {"text": prompt},
        "videoGenerationConfig": {
            "fps": 24,
            "durationSeconds": 6,
            "dimension": "1280x720"
        }
    }
    
    output_config = {"s3OutputDataConfig": {"s3Uri": output_s3_uri}}
    
    response = bedrock_runtime.start_async_invoke(
        modelId="amazon.nova-reel-v1:0",
        modelInput=json.dumps(model_input),
        outputDataConfig=output_config
    )
    
    invocation_arn = response["invocationArn"]
    
    # You might want to implement a way to check the job status,
    # as Lambda functions have a maximum execution time
    
    return {
        'statusCode': 200,
        'body': json.dumps('Video generation job started')
    }

Remember to grant your Lambda function the necessary permissions to access Bedrock and S3. Also, consider Lambda's execution time limits and implement appropriate error handling and status checking mechanisms.
Sources
Generate a video - Amazon Nova
Use Amazon Nova Reel to generate a video from a text prompt - AWS SDK Code Examples
Use Amazon Nova Reel to generate a video from a text prompt - Amazon Bedrock

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions