DEV Community

Cover image for AWS Serverless: Using Managed DeepSeek R1 with Amazon Bedrock, Lambda & API Gateway
Girish Bhatia
Girish Bhatia

Posted on

AWS Serverless: Using Managed DeepSeek R1 with Amazon Bedrock, Lambda & API Gateway

In my previous article, I explained how the DeepSeek R1 Distilled model can be used with Amazon Bedrock by storing it in an S3 bucket and importing it before invoking it via AWS Lambda and API Gateway.

In this article, I will explore a simpler and more efficient approach, using the fully managed DeepSeek R1 model with Amazon Bedrock, AWS Lambda, and API Gateway in a serverless environment. This eliminates the need to manually store and import the model, allowing you to integrate DeepSeek R1 into your applications without managing any infrastructure.

Amazon announced support for the fully managed DeepSeek R1 model in Amazon Bedrock on March 10, 2025. With this update, you no longer need to download the model, store it in Amazon S3, or use Bedrock’s custom model feature, everything is managed seamlessly by AWS.

Before diving in, let’s review the architecture diagram to understand how these components interact.

Image arch

Introduction to Amazon Bedrock

Amazon Bedrock is a fully managed service that provides access to a variety of foundation models, including Anthropic Claude, AI21 Jurassic-2, Stability AI, Amazon Titan, and others.

As a serverless offering from Amazon, Bedrock enables seamless integration with popular foundation models (FMs). It also allows you to privately customize these models with your own data using AWS tools, eliminating the need to manage any infrastructure.

Additionally, Bedrock supports the import of custom models.

Overview of DeepSeek R1 Model

The DeepSeek R1 model is a text-to-text language model designed to handle a wide range of natural language processing (NLP) tasks. It excels in transforming input text into meaningful and contextually relevant output, making it ideal for tasks such as text generation, summarization and question-answering.

As a fully managed model on Amazon Bedrock, DeepSeek R1 simplifies integration by removing the need for manual deployment and infrastructure management. It processes input text and generates coherent, context-aware responses, which can be leveraged in chatbots, customer support systems, content creation, and more.

Request Access to DeepSeek R1 Model

Before you can use the model, you need to request the access to the model.

Select DeepSeek R1 and click on Modify Access.

Image deepseekr1

Request Model Access

Image reqaccess

Review and submit the model access request.

Image submitreq

Please review that access has been granted to the model.

Image reviewaccess

Validate the Model Using Amazon Bedrock Playground

Once you have access to the model, you can start using it via Bedrock Playground:

Prompt: Please suggest 3 places to visit in NYC.

Image playground

Review AWS SAM template

The AWS Serverless Application Model (SAM) template defines the infrastructure required for the lambda function and API.

Here’s what the SAM template for this solution looks like:

Image template

Review AWS Lambda function (Python/Boto3 Library)

Lambda function is developed using Python and uses the Boto3 library to interact with Amazon Bedrock through Lambda and API.

Image lambda

Build function locally using AWS SAM

Command to build the function locally is SAM Build.

Image sambuild

Once code is successfully build, it is ready to be invoked.

Invoke function locally using AWS SAM

Command to invoke the function is sam local invoke -e

Image localinvoke

Deploy function using AWS SAM

Image deploy

Invoke the Model with Amazon Bedrock via API/Lambda

I am using Postman to pass the prompt and review the responses.

Image prompt2

Cleanup - Delete resources

Once done with this exercise, ensure to delete all the resources created so that these resources do not incur charges impacting overall cloud cost and budget.

Since these resources were build and deployed using AWS SAM, these can be deleted using AWS SAM command.

Command: sam delete

You can also delete the resources via AWS Console.

Conclusion

In this article, I demonstrated how to use the managed DeepSeek model with Amazon Bedrock. Since this is a serverless offering, there was no infrastructure that I needed to provision to use this model. I used the AWS CLI, AWS Management Console, AWS SAM, and Postman to validate the API.

For this solution, I used Python/Boto3 to create an API integrated with Bedrock via a Lambda function.

I hope you found this article both helpful and informative!

Thank you for reading!

Watch the video here:

https://www.youtube.com/watch?v=DNfxnxYYA4s

π’’π’Ύπ“‡π’Ύπ“ˆπ’½ ℬ𝒽𝒢𝓉𝒾𝒢
𝘈𝘞𝘚 𝘊𝘦𝘳𝘡π˜ͺ𝘧π˜ͺ𝘦π˜₯ 𝘚𝘰𝘭𝘢𝘡π˜ͺ𝘰𝘯 𝘈𝘳𝘀𝘩π˜ͺ𝘡𝘦𝘀𝘡 & π˜‹π˜¦π˜·π˜¦π˜­π˜°π˜±π˜¦π˜³ 𝘈𝘴𝘴𝘰𝘀π˜ͺ𝘒𝘡𝘦
𝘊𝘭𝘰𝘢π˜₯ π˜›π˜¦π˜€π˜©π˜―π˜°π˜­π˜°π˜¨π˜Ί 𝘌𝘯𝘡𝘩𝘢𝘴π˜ͺ𝘒𝘴𝘡

Top comments (0)