Jira API to Lambda (urllib3)

Hemali Patel
2 min readMay 12, 2021

--

How to Connect to Jira API via AWS Lambda

In this script, I will be going over how to make requests to the Jira API using the urllib3 in AWS Lambda. The response data from the request will be captured in a JSON format, formatted into a txt file, and then sent to an S3 bucket.

AWS to Jira API workflow

Project Requirements:

  • Jira API Token
  • AWS Lambda Access

Setting Up:

It is important to note, that certain calls to access the Jira API requires elevated privileges. Ensure the permissions are granted for the account/email making the request to the Jira API.

  • Get Jira API Token
  • Determine Jira API URL

Example URL: “https://yourdomain.atlassian.com/rest/api/3/applicationrole"

  • If the script is sending files to the bucket, ensure Lambda has the correct IAM permissions for access to the bucket.

<Script>

import json
import urllib3
import boto3
def lambda_handler(event, context):
s3 = boto3.resource('s3')
http = urllib3.PoolManager()
headers = urllib3.make_headers(basic_auth='email:x')
url = 'https://your-domain.atlassian.net/rest/api/3/X/X'

r = http.request(
'GET',
url,
headers=headers
)
data_get = (json.loads(r.data.decode('utf-8')))

datalist = json.dumps(
data_get,
sort_keys=False,
indent=4,
separators=(',', ': ')
)

s3.Object('s3bucketname', 'list.json').put(Body = datalist)

<Script> Explained

  • Using the boto3 library — import the s3 as a boto3.resource
  • In basic_auth: enter the email that will be used to access the API, and the token created under the same account. Replace ‘email’ with the email address and the‘x’ with the token. Ensure that ‘:’ remains in the midddle.
  • The http.request will take the defined URL, and the basic authentication in the headers to make the call to the API.
  • The requested data will get formatted as .json
  • The s3.object will locate the s3 bucket in your environment, set a title to the file, and put the body as the requested data from above in the file.

For Reference

--

--