-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamdafunction.py
37 lines (28 loc) · 1.11 KB
/
lamdafunction.py
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
import base64
import logging
import json
import boto3
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
print('Loading Lambda function')
runtime=boto3.Session().client('sagemaker-runtime')
endpoint_Name='pytorch-inference-2024-05-31-21-53-16-480'
def lambda_handler(event, context):
print('Context:::',context)
print('EventType::',type(event))
bs=event
runtime=boto3.Session().client('sagemaker-runtime')
response=runtime.invoke_endpoint(EndpointName=endpoint_Name,
ContentType="application/json",
Accept='application/json',
#Body=bytearray(x)
Body=json.dumps(bs))
result=response['Body'].read().decode('utf-8')
sss=json.loads(result)
return {
'statusCode': 200,
'headers' : { 'Content-Type' : 'text/plain', 'Access-Control-Allow-Origin' : '*' },
'type-result':str(type(result)),
'COntent-Type-In':str(context),
'body' : json.dumps(sss)
}