boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
8.97k stars 1.86k forks source link

UnknownServiceError: Unknown service: 'personalize-runtime'. #1858

Closed rohanhodarkar closed 5 years ago

rohanhodarkar commented 5 years ago

Hi,

I am trying to run real-time recommendations from AWS Personalize campaign in AWS Lambda following below code mentioned in the documentation .

import boto3

if __name__ == "__main__":

    personalizert = boto3.client('personalize-runtime', region_name='us-west-2')

    response=personalizert.get_recommendations(
        campaignArn="Campaign ARN",
        userId='User ID',
        itemId='Item ID')

    print("Recommended items")

    for item in response['itemList']:
            print (item['itemId'])

https://docs.aws.amazon.com/personalize/latest/dg/getting-recommendations.html

However I am getting below error:

UnknownServiceError: Unknown service: 'personalize-runtime'. Valid service names are: acm, acm-pca, alexaforbusiness, amplify, apigateway, apigatewaymanagementapi, apigatewayv2, application-autoscaling, appmesh, appstream, appsync, athena, autoscaling, autoscaling-plans, backup, batch, budgets, ce, chime, cloud9, clouddirectory, cloudformation, cloudfront, cloudhsm, cloudhsmv2, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, codebuild, codecommit, codedeploy, codepipeline, codestar, cognito-identity, cognito-idp, cognito-sync, comprehend, comprehendmedical, config, connect, cur, datapipeline, datasync, dax, devicefarm, directconnect, discovery, dlm, dms, docdb, ds, dynamodb, dynamodbstreams, ec2, ecr, ecs, efs, eks, elasticache, elasticbeanstalk, elastictranscoder, elb, elbv2, emr, es, events, firehose, fms, fsx, gamelift, glacier, globalaccelerator, glue, greengrass, guardduty, health, iam, importexport, inspector, iot, iot-data, iot-jobs-data, iot1click-devices, iot1click-projects, iotanalytics, kafka, kinesis, kinesis-video-archived-media, kinesis-video-media, kinesisanalytics, kinesisanalyticsv2, kinesisvideo, kms, lambda, lex-models, lex-runtime, license-manager, lightsail, logs, machinelearning, macie, marketplace-entitlement, marketplacecommerceanalytics, mediaconnect, mediaconvert, medialive, mediapackage, mediastore, mediastore-data, mediatailor, meteringmarketplace, mgh, mobile, mq, mturk, neptune, opsworks, opsworkscm, organizations, pi, pinpoint, pinpoint-email, pinpoint-sms-voice, polly, pricing, quicksight, ram, rds, rds-data, redshift, rekognition, resource-groups, resourcegroupstaggingapi, robomaker, route53, route53domains, route53resolver, s3, s3control, sagemaker, sagemaker-runtime, sdb, secretsmanager, securityhub, serverlessrepo, servicecatalog, servicediscovery, ses, shield, signer, sms, sms-voice, snowball, sns, sqs, ssm, stepfunctions, storagegateway, sts, support, swf, transcribe, transfer, translate, waf, waf-regional, workdocs, worklink, workmail, workspaces, xray

Seems like personalize-runtime service is not present in boto3 yet.

Boto3 version used = 1.9.86 Region = us-east-1

Thanks in advance.

Rohan Hodarkar

kapilt commented 5 years ago

lambda ships fairly ancient versions of boto3, its unclear why they stopped updating, but at least for py 2.7 and 3.6 its a release from august 2018, 3.7 has a lib from early november 2018. in general if your using new services in lambda you should bundle and package your botocore/boto3 versions, ideally via layer.

rohanhodarkar commented 5 years ago

I have used latest boto3 version i.e. 1.9.86 and this latest version doesn't have 'personalize-runtime' service. Is it something development? If yes, what is the ETA for its production?

stealthycoin commented 5 years ago

I have no idea what that is, its not a released model or service as far as I can tell.

rohanhodarkar commented 5 years ago

AWS Personalize is a ML recommendation engine service by Amazon. This service was released back in end of Nov 2018. See official page of this service here: https://aws.amazon.com/personalize/

kapilt commented 5 years ago

you'll need to package up the service files for use in lambda, https://docs.aws.amazon.com/personalize/latest/dg/aws-personalize-set-up-aws-cli.html

you'll typically do that via setting AWS_DATA_PATH per to point to the directory within your lambda upload that contains your uploaded service files. AWS_DATA_PATH=$LAMBDA_TASK_ROOT/path_in_zip/ https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#environment-variable-configuration

rohanhodarkar commented 5 years ago

Thank you @kapilt ..

niyando commented 5 years ago

@rohanhodarkar were you able to solve this?

rohanhodarkar commented 5 years ago

@niyando Yes. You need to follow steps mentioned in the link provided by @kapilt above. But it will work only on your local environment NOT Lambda.

My requirement changed as I we were not able to call it from Lambda.

You will have to open ticket against AWS team to get the solution probably..

niyando commented 5 years ago

@rohanhodarkar Thanks. I just need it to work on my local boto3 SDK. Will try the steps mentioned in the link.

piyush2dev commented 5 years ago

Can anybody please help me. I need to use personalize-runtime in lambda but getting UnknownServiceError: Unknown service: 'personalize-runtime'. How to call this service in lambda. Please help. @kapilt - Can u please help.

mfund0 commented 5 years ago

Here's one way you can do this -- by using Lambda Layers and manually adding the models to the sdk.

Steps:

  1. Create a site-packages lib directory

    LIB=boto3-with-personalize/python/lib/python3.6/site-packages 
    mkdir -p $LIB 
  2. Install the library to LIB

    pip3 install boto3 -t $LIB 
  3. Download the service models, rename them & put them in the botcore/data directory

    
    wget -N https://s3-us-west-2.amazonaws.com/personalize-cli-json-models/personalize.json
    wget -N https://s3-us-west-2.amazonaws.com/personalize-cli-json-models/personalize-runtime.json

rename each one of them to service-2.json

move them to: /boto3-latest/python/lib/python3.6/site-packages/botocore/data/personalize/2018-05-28/ /boto3-latest/python/lib/python3.6/site-packages/botocore/data/personalize-runtime/2018-05-28/


4. Zip all the dependencies to /tmp/boto3-with-personalize.zip

cd boto3-with-personalize zip -r /tmp/boto3-with-personalize .


5. Publish the layer

aws lambda publish-layer-version --layer-name boto3-with-personalize --zip-file fileb:///tmp/boto3-with-personalize.zip


The above should return an ARN for a layer in the form:

arn:aws:lambda:region:ACC_ID:layer:boto3-with-personalize:1"


6. Add the layer to the function's configuration

aws lambda update-function-configuration --function-name --layers arn:aws:lambda:region:ACC_ID:layer:boto3-with-personalize:1