我在 S3 中有一些数据,我想创建一个 lambda 函数来预测我部署的 aws sagemaker 端点的输出,然后我再次将输出放入 S3。在这种情况下是否有必要创建一个像此链接中描述的 api 网关?在 lambda 函数中我必须放什么。我希望放置(在哪里可以找到数据,如何调用端点,在哪里放置数据)
import boto3
import io
import json
import csv
import os
client = boto3.client('s3') #low-level functional API
resource = boto3.resource('s3') #high-level object-oriented API
my_bucket = resource.Bucket('demo-scikit-byo-iris') #subsitute this for your s3 bucket name.
obj = client.get_object(Bucket='demo-scikit-byo-iris', Key='foo.csv')
lines= obj['Body'].read().decode('utf-8').splitlines()
reader = csv.reader(lines)
import io
file = io.StringIO(lines)
# grab environment variables
runtime= boto3.client('runtime.sagemaker')
response = runtime.invoke_endpoint(
EndpointName= 'nilm2',
Body = file.getvalue(),
ContentType='*/*',
Accept = 'Accept')
output …Run Code Online (Sandbox Code Playgroud)