aws / aws/amazon-sagemaker-examples

DeepAR lambda Endpoint issue

Open
#1,095 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
11k
Forks
7k
Avg merge
8h 29m
Merged PRs (30d)
8

Description

Hi,

I built a DeepAR prediction model endpoint. I want to invoke it in the lambda function.
`import json
import os
import io
import csv
import boto3
from boto3.dynamodb.conditions import Key, Attr
import time
milliseconds = int(round(time.time() * 1000))
try:
import requests
except ImportError:
from botocore.vendored import requests

ENDPOINT_NAME = os.environ['ENDPOINT_NAME']
runtime= boto3.client('runtime.sagemaker')

def get_msg_from_DynamoDB(execution_id,device_id):
aws_access_key_id_ = 'AKIAV2Q2LEBKVYTFJKQY'
aws_secret_access_key_ ='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'
table_name = 'iot-data-dump-001'

dynamodb = boto3.resource('dynamodb',
aws_access_key_id=aws_access_key_id_,
aws_secret_access_key= aws_secret_access_key_)
table = dynamodb.Table(table_name)

playload = table.query(KeyConditionExpression = Key('pKey').eq('2020-03-17'),
ScanIndexForward = False,
FilterExpression = Attr('raw_message.DeviceID').eq('device97'))


playload['Items'] = playload['Items'][:30]

list_var = []
list_time = []
index = 0;
for item in playload['Items']:
list_var.append(float(item['raw_message']['VarValue']))
list_time.append(item['raw_message']['TimeString'][:10] +" "+ item['raw_message']
result = {}
result = {"start":timestamp,"target":list_var}

print(result)
result = json.dumps(result)

response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='application/json',
Body=result)
print(response)
pre = json.loads(response['Body'].read().decode())
print(pre)

return playload;`

One example of endpoint input is
{'start': '2020-03-17 22:59:42', 'target': [0.0, 0.0, 0.0, 1.612775, 1.843171, 1.382379, 719.7584, 793.2548, 796.25, 796.7109, 798.7844, 798.7844, 805.9266, 806.8482, 808.4611, 812.8386, 811.4562, 817.6769, 818.368, 819.9809, 821.5937, 819.9809, 825.0495, 828.7359, 830.1183, 832.4223, 833.1134, 836.5693, 837.0302, 842.79]}

I encountered this problem:
![image](https://user-images.githubusercontent.com/23226356/77017231-d28cb080-69c9-11ea-8219-18b07f827e63.png)
I think I did not get the right data format as the endpoint input. But I do not know what is the right data format. Can anyone help me? Thanks!!

Contributor guide

Open the contributing guide

Research direction

The payload identifies a Lambda function and its runtime.invoke_endpoint call, but no repository file or test. Start by reproducing the reported endpoint invocation with the shown input and inspect the linked error image; done means the Lambda request is accepted and the response is decoded successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.