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