Serverless Generative AI: Amazon Bedrock Running in Lambda

AWS Developers · Beginner ·🔧 Backend Engineering ·2y ago

Key Takeaways

This video demonstrates how to get Amazon Bedrock working in a Lambda function by updating the Boto 3 version using a Lambda layer, and configuring the execution time and permissions to talk to the Bedrock service. The video covers the use of Amazon Bedrock, Boto 3, Lambda layers, and the AWS CLI to deploy a serverless generative AI application.

Full Transcript

have you tried getting Amazon Bedrock working with a Lambda function well in this video that's exactly what we're going to take a look at let's jump into the AWS console and take a look here I have Amazon Bedrock just a quick recap here um I've got my models enabled currently in this in this account so if I scroll down go to model access you'll see that in this particular region I've got access to a whole ton of different models if you're wondering how all of this works and why all of this works and how to use the console a little bit more uh in detail then there's a link up in the corner somewhere up there which will go to a video where I walk through all of that now let's jump into the uh Lambda console itself so here I've got a Lambda function which I've already created so it's a python 3.11 function um it's called My Bedrock function because no imagination okay let's scroll down um and you can see the code here so I'm importing boto three I'm using the Bedrock runtime um object from the Bedrock client rather um and then following the bouncing ball here so this is the almost boilerplate code I've got this very simple prompt uh write a fictional article about sorry write an article about a fictional Planet Fubar um I'm then inserting that into these keyword arguments these arguments I actually grabbed straight out of the console so definitely using that as part of my um development process then get a response back back from the Amazon Bedrock client by sending all of those keyword arguments in and we get the response back out okay so brilliant um is that what this video is about not quite let me show you now I'm going to click test and we're going to see what comes back from this um request when we run this model and we get this response coming back saying unknown service Bedrock runtime so basically boto 3 doesn't know about the bread Rock runtime what's happening there I mean bedrocks in my account the models are enabled why can't I get access to it and the reason is because the SDK version that I'm using so Bodo 3 SDK version was released prior to Amazon Bedrock so it doesn't know about Amazon Bedrock he doesn't know how to work with it and this is the default currently the default SDK which is available inside of the Lambda environment so we need to update the version of boto 3 that this code has access to now there's a couple of different ways of doing that if you deploy Lambda functions with build pipeline processes such as the Sam framework then inside of there just go into your requirements.txt type in boto3 so make sure that it's pulling in the latest version of boto 3 every time it's zipping up your Lambda function and pushing it out but what about in this scenario here I'm experimenting and I've just got some code that I'm working with inside of the console well I can use a Lambda layer so a Lambda layer is a zip function that we can provide to the Lambda environment and we can say to any function that we have when you run make sure that you're pulling the libraries in the first instance out of this ZIP file so let's go ahead and create a Lambda layer with the latest version of Bodo 3 and get this Lambda function working okay so to do that I'm going to load the cloud shell so if I just click this button here right in the middle well with my zoom level anyway right in the middle at the top of the console page so here is a command line environment right here inside of my AWS console so everything I'm doing here is in the cloud it's not actually happening on my local machine and I can use this environment to create a Lambda layer and upload it there are lots of ways you can do this but this is one of the ways that you can do it okay so what I'm going to do is I'm going to install the latest version of boto 3 into a folder then I'm going to zip it up and make that my Lambda layer so the first thing I'm going to do is I'm going to make a directory and I'm going to call this a Bedrock layer because no imagination okay so let's make that and let's then um change directory into that folder so we've just got somewhere clean to work and then inside of there I'm going to make a folder um or a directory called Python and it's very important that this is actually called python the other folder not so much of a problem you can call that anything you like this one needs to be called python um because this is where we're going to install boto 3 into and it's the path that the Lambda layer will be looking for so if I just do a quick directory listing here is my empty folder called python now I'm going to use the PIP package manager to install boto 3 into here and I do that like this I type in PIP um and I'm going to use pip three for Python 3 um then going to ask it to um install um hyphen t for Target so I want to put it into this folder so I'm going to say into the python folder and what do I want to install in there I want to install boto 3 so this is going to get PIP to specifically install the latest version of boto 3 into that python folder there so hit enter on that and off it goes and it should just rattle through all of those files now we can have a look to make sure it's done that in just a second when it's finished and it should be finished now is there we go okay so let's um again so we've got our python folder there and if we do a directory listing um inside of that python folder there it is there's all of the boto3 LI uh Library files that we want to zip up okay so again we are in that one step down we're looking we're in the same folder as that python folder what we now need to do is zip everything up that we can use that then as the Lambda layer and zip is installed inside of this environment so I can say zip um hyphen R and then I'm going to call this uh Bedrock layer. zip so obviously that's the file name that I'm looking to create and then I press period because I want to zip everything that's in this current location so that should make my zip file and you can see it adding in all of those files there again all of this happening up in the cloud none of this is happening on my machine so if I do a directory listing now then I can see that Bedrock layer. zip file right there now I need to upload that as a Lambda layer now I could just download this go to the console page for Lambda upload it from there but I'm not going to do that I'm going to do it again right here in the command line so I'm going to use the AWS CLI for this so the AWS command line tool so I'm going to call AWS I'm going to call AWS Lambda because I'm using Lambda features here and then I'm going to say publish layer version and then I'm going to make sure I've spelled it right uh I haven't version okay AWS Lambda publish layer version then I need to give a layer name and that layer name for me will be called Bedrock layer because that seems like a good idea um and then I need to show it the file that I want to upload and so the file is going to be be uh done like this so zip hyphen hyphen zip um file because it's a zip file that we have um and then I have fileb colon SL a binary file I'm pointing it to and it's the binary file we just made so let me make sure I've got all of that right um so file B Bedrock layer zip that looks correct let's press enter on that and then again in the cloud environment it's going to take that um zip file and upload it at has a layer which it's done and it's go given me this large response back all right let's go and see this inside of the console so let's uh close this shell for the moment I'm going to scroll up here and go to my menu and my Lambda menu I'm going to go to layers and inside of here if I press refresh I I have it indeed I've got my Bedrock layer here now this is version two because I have created one of these in the past but everything that I did basically just uploaded this Lambda layer if I click in on that um I can see details about it and I can also see here the Arn so the resource name for this particular layer that we've created so I'm going to copy that then I'm going to go back to my Lambda function um so there's my Bedrock function and here you'll see right at the top here this layers with a zero here so it's basically showing us that we're not using any Lambda layers at the moment so so let's go ahead and click layers takes us to this layers box I can say add a layer I'm going to add the layer directly from the Arn so paste that into there and click add it wors around for just a moment and it should take us back in a second once it's done that and now we've got a one inside of that bracket there so it's got a Lambda layer if I now scroll down and click the test button well let's get rid of that and let's get rid of that right now if I click the test button then when it comes back this time hopefully everything's been successful now whilst we're doing this and we're waiting for this generation you'll notice that this particular generation is taking a little while because I've asked it to create an entire um article so one of the things I also had to do with this Lambda function is change the execution time up from the default 3 seconds to something else I actually gave it I think 3 minutes and the other thing I had to do was make sure that it's got I permissions to talk to the Bedrock service so you can see now that on with those things set and also with the upto-date version of the boto3 library there as well here is our generation that has come out of that that model so here's a draft article about a fictional planet called fuar okay hopefully that was useful and that answered some of the questions that you have about getting started with Amazon Bedrock whilst you're looking for more information about about generative Ai and about bedrock and about all things AWS they'll please do subscribe to this channel um add more questions below here if you've got them and I'll see what I can do my absolute best to answer those for you and also take a look at community. AWS so here in community. AWS / generative AI it's available just as a menu option this is a place that we've got where we're compiling together articles about generative AI so not just about bedrock not just about Sage maker jump start um but about generative AI the core technology how it works and how you can get the best out of it when you're building applications using this amazing new set of technology that we have available to us so please do leave a like on this video If you enjoyed it ask me questions in the comments and until the next time I will see you in the next video

Original Description

In this video Mike takes a look at getting Amazon Bedrock working in a Lambda function. This is a point in time video as things will change, but for now, you need to bring an up-to-date version of the SDK with you in to your Lambda function. Resources: 🌐 Get started with Amazon Bedrock: https://aws.amazon.com/bedrock/ Follow AWS Developers! 🐦 Twitter: https://www.twitter.com/awsdevelopers 💼 LinkedIn: https://www.linkedin.com/showcase/aws-developers/ 👾 Twitch: https://twitch.tv/aws 📺 Instagram: https://www.instagram.com/awsdevelopers/?hl=en Follow Mike Chambers! 💼 LinkedIn: https://www.linkedin.com/in/mikegchambers/ #amazonbedrock #generativeai #lambda
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from AWS Developers · AWS Developers · 0 of 60

← Previous Next →
1 Using Microsoft Active Directory across On-premises and Cloud Workloads
Using Microsoft Active Directory across On-premises and Cloud Workloads
AWS Developers
2 What is Cloud Computing with AWS? | Hebrew Webinar
What is Cloud Computing with AWS? | Hebrew Webinar
AWS Developers
3 Best Practices for Getting Started with AWS | Hebrew Webinar
Best Practices for Getting Started with AWS | Hebrew Webinar
AWS Developers
4 Best Practices for Using AWS Identity and Access Management (IAM) Roles
Best Practices for Using AWS Identity and Access Management (IAM) Roles
AWS Developers
5 Building Scalable Web Apps | Hebrew Webinar
Building Scalable Web Apps | Hebrew Webinar
AWS Developers
6 Dev & Test on the AWS Cloud | Hebrew Webinar
Dev & Test on the AWS Cloud | Hebrew Webinar
AWS Developers
7 Storage & Backup on AWS | Hebrew webinar
Storage & Backup on AWS | Hebrew webinar
AWS Developers
8 Disaster Recovery on AWS | Hebrew Webinar
Disaster Recovery on AWS | Hebrew Webinar
AWS Developers
9 AWS Israel News  | Episode 1
AWS Israel News | Episode 1
AWS Developers
10 Security Best Practices on AWS | Hebrew Webinar
Security Best Practices on AWS | Hebrew Webinar
AWS Developers
11 Ready: Introduction to AI on AWS | Hebrew Webinar
Ready: Introduction to AI on AWS | Hebrew Webinar
AWS Developers
12 Set: What is ML for developers? | Hebrew Webinar
Set: What is ML for developers? | Hebrew Webinar
AWS Developers
13 Go!: Building your own ChatBot with Amazon Lex | Hebrew Webinar
Go!: Building your own ChatBot with Amazon Lex | Hebrew Webinar
AWS Developers
14 And Beyond: Amazon Sagemaker | Hebrew Webinar
And Beyond: Amazon Sagemaker | Hebrew Webinar
AWS Developers
15 Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech Talks
Building API-Driven Microservices with Amazon API Gateway - AWS Online Tech Talks
AWS Developers
16 Understanding AWS Secrets Manager - AWS Online Tech Talks
Understanding AWS Secrets Manager - AWS Online Tech Talks
AWS Developers
17 Best Practices for Building Enterprise Grade APIs with Amazon API Gateway - AWS Online Tech Talks
Best Practices for Building Enterprise Grade APIs with Amazon API Gateway - AWS Online Tech Talks
AWS Developers
18 Build, Train and Deploy Machine Learning Models on AWS with Amazon SageMaker - AWS Online Tech Talks
Build, Train and Deploy Machine Learning Models on AWS with Amazon SageMaker - AWS Online Tech Talks
AWS Developers
19 AWS Israel News | Episode 2 | re:Invent
AWS Israel News | Episode 2 | re:Invent
AWS Developers
20 AWS Floor28 News - January
AWS Floor28 News - January
AWS Developers
21 AWS Floor28 News - February - Hebrew
AWS Floor28 News - February - Hebrew
AWS Developers
22 AWS Floor28 News - March - Hebrew
AWS Floor28 News - March - Hebrew
AWS Developers
23 AWS Floor28 News - April - Hebrew
AWS Floor28 News - April - Hebrew
AWS Developers
24 AWS Floor28 News - May - Hebrew
AWS Floor28 News - May - Hebrew
AWS Developers
25 Authentication for Your Applications: Getting Started with Amazon Cognito - AWS Online Tech Talks
Authentication for Your Applications: Getting Started with Amazon Cognito - AWS Online Tech Talks
AWS Developers
26 AWS Floor28 News - June - Hebrew
AWS Floor28 News - June - Hebrew
AWS Developers
27 AWS Floor28 News - July - Hebrew
AWS Floor28 News - July - Hebrew
AWS Developers
28 Enriching your app with Image Recognition and AWS AI Services - AWS Webinar - Hebrew
Enriching your app with Image Recognition and AWS AI Services - AWS Webinar - Hebrew
AWS Developers
29 Personalize, Forcast, and Textract - AWS Webinar - Hebrew
Personalize, Forcast, and Textract - AWS Webinar - Hebrew
AWS Developers
30 Managing Your ML Development Lifecycle with Amazon SageMaker - AWS Webinar - Hebrew
Managing Your ML Development Lifecycle with Amazon SageMaker - AWS Webinar - Hebrew
AWS Developers
31 Running your ML code in Amazon Sagemaker - AWS Webinar - Hebrew
Running your ML code in Amazon Sagemaker - AWS Webinar - Hebrew
AWS Developers
32 Get Started in Minutes with Amazon Connect in Your Contact Center - AWS Online Tech Talks
Get Started in Minutes with Amazon Connect in Your Contact Center - AWS Online Tech Talks
AWS Developers
33 AWS Floor28 News - August - Hebrew
AWS Floor28 News - August - Hebrew
AWS Developers
34 AWS Floor28 News - September - Hebrew
AWS Floor28 News - September - Hebrew
AWS Developers
35 Deep Dive on Amazon EventBridge - AWS Online Tech Talks
Deep Dive on Amazon EventBridge - AWS Online Tech Talks
AWS Developers
36 Advanced Serverless Orchestration with AWS Step Functions - AWS Online Tech Talks
Advanced Serverless Orchestration with AWS Step Functions - AWS Online Tech Talks
AWS Developers
37 Living on the Edge - an Introduction to  Amazon CloudFront and Lambda@Edge  - Hebrew Webinar
Living on the Edge - an Introduction to Amazon CloudFront and Lambda@Edge - Hebrew Webinar
AWS Developers
38 AWS Floor28 News - October - Hebrew - YouTube
AWS Floor28 News - October - Hebrew - YouTube
AWS Developers
39 What's New with AWS Storage - AWS Online Tech Talks
What's New with AWS Storage - AWS Online Tech Talks
AWS Developers
40 How to Build a Compelling Migration Business Case Using TSO Logic - AWS Online Tech Talks
How to Build a Compelling Migration Business Case Using TSO Logic - AWS Online Tech Talks
AWS Developers
41 Configuring and Managing Amazon S3 Replication - AWS Online Tech Talks
Configuring and Managing Amazon S3 Replication - AWS Online Tech Talks
AWS Developers
42 AWS Floor28 News - November - Hebrew
AWS Floor28 News - November - Hebrew
AWS Developers
43 Using Relational Databases with AWS Lambda - Easy Connection Pooling - AWS Online Tech Talks
Using Relational Databases with AWS Lambda - Easy Connection Pooling - AWS Online Tech Talks
AWS Developers
44 AWS Floor28 News - December 2019 - Hebrew
AWS Floor28 News - December 2019 - Hebrew
AWS Developers
45 AWS Floor28 News - January 2020 - Hebrew
AWS Floor28 News - January 2020 - Hebrew
AWS Developers
46 Top 10 Data Migration Best Practices - AWS Online Tech Talks
Top 10 Data Migration Best Practices - AWS Online Tech Talks
AWS Developers
47 How to Use Azure Active Directory with AWS SSO - AWS Online Tech Talks
How to Use Azure Active Directory with AWS SSO - AWS Online Tech Talks
AWS Developers
48 AWS Tips & Tricks - Amazon Redshift Advisor - Hebrew
AWS Tips & Tricks - Amazon Redshift Advisor - Hebrew
AWS Developers
49 AWS Tips & Tricks - Amazon Redshift Elastic Resize - Hebrew
AWS Tips & Tricks - Amazon Redshift Elastic Resize - Hebrew
AWS Developers
50 AWS Tips & Tricks - Amazon Redshift Spectrum - Hebrew
AWS Tips & Tricks - Amazon Redshift Spectrum - Hebrew
AWS Developers
51 AWS Tips & Tricks - Savings Plans & Cost Explorer - Hebrew
AWS Tips & Tricks - Savings Plans & Cost Explorer - Hebrew
AWS Developers
52 AWS Tips & Tricks - Amazon Redshift Concurrency Scaling - Hebrew
AWS Tips & Tricks - Amazon Redshift Concurrency Scaling - Hebrew
AWS Developers
53 AWS Tips & Tricks - Training Models with Amazon SageMaker - Hebrew
AWS Tips & Tricks - Training Models with Amazon SageMaker - Hebrew
AWS Developers
54 AWS Tips & Tricks - Auto Model Tuning with Amazon SageMaker - Hebrew
AWS Tips & Tricks - Auto Model Tuning with Amazon SageMaker - Hebrew
AWS Developers
55 AWS Tips & Tricks - Amazon Comprehend - Hebrew
AWS Tips & Tricks - Amazon Comprehend - Hebrew
AWS Developers
56 Understanding High Availability and Disaster Recovery Features for Amazon RDS for Oracle
Understanding High Availability and Disaster Recovery Features for Amazon RDS for Oracle
AWS Developers
57 Amazon Forecast  – Forecasting  - From Months to Days (Hebrew)
Amazon Forecast – Forecasting - From Months to Days (Hebrew)
AWS Developers
58 Visualize your data with Amazon QuickSight (Hebrew)
Visualize your data with Amazon QuickSight (Hebrew)
AWS Developers
59 Amazon Kendra (Hebrew)
Amazon Kendra (Hebrew)
AWS Developers
60 AWS Floor28 News - AI/ML Special Edition
AWS Floor28 News - AI/ML Special Edition
AWS Developers

This video teaches how to deploy Amazon Bedrock in a Lambda function using a Lambda layer to update the Boto 3 version, and configure the execution time and permissions to talk to the Bedrock service. It covers the use of Amazon Bedrock, Boto 3, Lambda layers, and the AWS CLI to deploy a serverless generative AI application. By following this video, viewers can design and deploy their own serverless generative AI applications using Amazon Bedrock and Lambda functions.

Key Takeaways
  1. Update Boto 3 version using Lambda layer
  2. Install latest version of Boto 3 in a folder
  3. Zip the folder and use it as a Lambda layer
  4. Make a directory called Bedrock layer, then change directory into it
  5. Make a folder called Python, install boto3 into it, and zip it up
  6. Use the PIP package manager to install boto3 into the Python folder
  7. Zip up the contents of the Python folder
  8. Publish a layer version of the Bedrock layer using the AWS CLI, upload the zip file, and give it a layer name of Bedrock layer
  9. Upload Bedrock layer zip to Lambda
  10. Add Lambda layer to Bedrock function
💡 The key insight from this video is that Amazon Bedrock can be deployed in a Lambda function using a Lambda layer to update the Boto 3 version, and configuring the execution time and permissions to talk to the Bedrock service.

Related Reads

Up next
Indian Express Editorial Analysis by Chandan Sharma - 1 JULY 2026 | UPSC Current Affairs 2026
StudyIQ IAS
Watch →