Accessing REST API using AWS Lambda

2553
2
Jump to solution
01-03-2021 06:15 PM
DeanHowell1
Occasional Contributor III

I am trying to write a python script via they AWS Lambda interface to generate a token and then use that token to get various attributes of the ArcGIS portal. 

The question I have is how to set up Lambda to access the various libraries correctly?

The simple script I have is getting the following so I suspect I just don't have all the libraries installed but I don't know where that needs to happen in an AWS Lambda environment.

[ERROR] NameError: name 'request' is not defined

My script is a follows:

from urllib.parse import urlencode
from urllib.request import Request, urlopen
import json

#define variables
portalUrl = "https://admin.portal.arcgis"
username = 'yyyyyyy'
password = "xxxxxxx"

# Get a security token to append to all requests
def generateToken(username, password, portalUrl):

# Retrieves a token to be used with API requests.
headers = {'content-type': 'application/x-www-form-urlencoded'}
parameters = {'username': username,
'password': password,
'client': 'referer',
'referer': portalUrl,
'expiration': 60,
'f': 'json'}
url = portalUrl + '/sharing/rest/generateToken?'
response = request.post(url, data=parameters, headers=headers)

 

 

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

Think you've missed the capital letter.

response = request.post(url, data=parameters, headers=headers)

response = Request.post(url, data=parameters, headers=headers)

View solution in original post

2 Replies
DavidPike
MVP Frequent Contributor

Think you've missed the capital letter.

response = request.post(url, data=parameters, headers=headers)

response = Request.post(url, data=parameters, headers=headers)

DeanHowell1
Occasional Contributor III

Thanks @DavidPike , sometimes you can't see the forest for the trees 🙂

0 Kudos