Thursday, February 1, 2024

Step by Step Guide to Configure Amazon Bedrock with VPC Endpoints and PrivateLink

This video is step by step tutorial to setup AWS Bedrock with VPC Endpoints and PrivateLink to build secure and private generative AI applications.



 Steps:


Step 0: Make sure that Private subnet with private route table without any route to internet is there.

Step 1: Create 2 SG  = Bedrock-Endpoint-SG and Bedrock-Lambda-SG

Step 2: In Bedrock-Lambda-SG , ADD Bedrock-EndPoint-SG for all traffic in INBOUND, and OUTBOUND FOR 0.0.0.0

Step 3: In Bedrock-EndpointP-SG, Add Bedrock-Lambda-SG for all traffic in INBOUND and OUTBOUND 

Step 4: Create 2 endpoints bedrock, bedrock-runtime in private subnet and attach Bedrock-EndpointP-SG with both

Step 5: Create lambda function, set time to 15 seconds, and attach Bedrock-Lambda-SG, lambda execution role should have bedrock permissions


Lambda Code:


import boto3

import json


def lambda_handler(event,context):

    bedrock = boto3.client(

     service_name='bedrock', 

     region_name='us-east-1'

    )

     

    # Bedrock Runtime client used to invoke and question the models

    bedrock_runtime = boto3.client(

     service_name='bedrock-runtime', 

     region_name='us-east-1'

    )


    models = bedrock.list_foundation_models().get('modelSummaries')


    for model in models:

        print(model['modelName'] + ', Input=' + '-'.join(model['inputModalities']) + ', Output=' + ''.join(model['outputModalities']) + ', Provider=' + model['providerName'])

        

    return{

        'statusCode':200,

}

No comments: