Creating Jira Issues from Monitoring Alerts with AWS Lambda

Alerts from a monitoring system, failed pipeline runs and customer bug reports often need to end up as Jira issues. Copying them in by hand is slow and inconsistent, and Jira's built-in integrations don't always let you control how fields are mapped. A small webhook receiver that translates an incoming JSON payload into a Jira "create issue" call fills that gap.
This guide builds that receiver with AWS API Gateway and a Python Lambda function. It covers the two details that most tutorials get wrong: Jira Cloud's v3 API requires descriptions in Atlassian Document Format (ADF), not plain text, and a public webhook URL needs to verify who is calling it.
The Challenge: Bridging External Events to Jira Issues
The core problem lies in the 'last mile' of integration. Your monitoring system sends a JSON payload, your customer feedback tool has its own structure, and your CI/CD pipeline spits out logs. Jira, however, expects a specific API payload to create an issue. Simply forwarding the raw data rarely works, and building a full-fledged service just for this translation can be overkill.
Common scenarios demanding this kind of automation include:
- Monitoring Alerts: Automatically creating high-priority incidents in Jira when critical system thresholds are breached (e.g., from Datadog, Prometheus Alertmanager, New Relic).
- Customer Feedback: Turning specific feedback entries (e.g., from Zendesk, Intercom, custom forms) into bug reports or feature requests.
- CI/CD Failures: Creating tickets for build breaks, failed deployments, or security vulnerabilities detected in pipelines (e.g., from Jenkins, GitHub Actions, GitLab CI).
- Scheduled Tasks: Generating recurring tasks or reports based on cron jobs or internal system events.
Our goal is to build a lean, robust intermediary that receives a generic webhook payload from any external system, intelligently processes it, and then dispatches a well-formed request to Jira's API to create an issue. AWS Lambda, coupled with API Gateway, provides an ideal serverless backbone for this.
Architecture: A Serverless Webhook Listener
We'll use AWS Lambda as a compute service to run our custom logic without managing servers, and AWS API Gateway to provide a public, secure HTTPS endpoint for our external systems to send webhooks to. The flow is simple:
- An external system triggers an event and sends a JSON payload via HTTP POST to our API Gateway endpoint.
- API Gateway receives the request and forwards it to our Lambda function.
- The Lambda function verifies a shared secret, parses the payload, and builds a Jira API request.
- The Lambda function authenticates with Jira (using an API token) and calls the Jira Create Issue API.
- Jira creates the issue, and the Lambda function responds to the external system.
This architecture is incredibly flexible. The Lambda function can be written in Python, Node.js, Go, or any language supported by AWS Lambda, allowing for complex parsing, conditional logic, and integration with other AWS services if needed.
Step-by-Step Implementation
Let's walk through setting this up. For this example, we'll use Python for our Lambda function and assume we want to create a 'Bug' issue type with a summary and description.
Step 1: Set Up Your Jira Project and API Token
First, you'll need a Jira Cloud instance and a project configured with the issue types you want to create (e.g., 'Bug', 'Task', 'Story').
- Create a Jira API Token: Log in to Jira, go to your profile, then "Manage your account" > "Security" > "Create and manage API tokens". Generate a new token and copy it – you'll only see it once.
- Get Jira Base URL: This is typically
https://your-domain.atlassian.net. - Identify the project key and issue type: The project key is the prefix on issue numbers (e.g.,
DEVinDEV-123). Issue type IDs differ between Jira sites, so don't copy IDs from examples. List the types available to a project withGET /rest/api/3/issue/createmeta/{projectIdOrKey}/issuetypes. This guide uses the issue typename("Bug"), which works as long as the name exists in the target project.
Step 2: Create Your AWS Lambda Function
The function below does four things: rejects requests without the right shared secret, extracts fields from the alert, converts the description to ADF, and calls POST /rest/api/3/issue. It uses only the Python standard library, so there's nothing to bundle into the deployment package.
import base64
import hmac
import json
import os
import urllib.error
import urllib.request
JIRA_BASE_URL = os.environ["JIRA_BASE_URL"] # https://your-domain.atlassian.net
JIRA_EMAIL = os.environ["JIRA_EMAIL"]
JIRA_API_TOKEN = os.environ["JIRA_API_TOKEN"] # load from Secrets Manager in production
JIRA_PROJECT_KEY = os.environ["JIRA_PROJECT_KEY"]
JIRA_ISSUE_TYPE = os.environ.get("JIRA_ISSUE_TYPE_NAME", "Bug")
WEBHOOK_SECRET = os.environ["WEBHOOK_SECRET"]
def adf_paragraphs(*lines):
"""Jira Cloud's v3 API only accepts descriptions in Atlassian Document Format."""
return {
"type": "doc",
"version": 1,
"content": [
{"type": "paragraph", "content": [{"type": "text", "text": line}]}
for line in lines if line
],
}
def adf_code_block(text, language="json"):
return {"type": "codeBlock", "attrs": {"language": language},
"content": [{"type": "text", "text": text}]}
def respond(status, body):
return {"statusCode": status, "body": json.dumps(body)}
def lambda_handler(event, context):
# Header-name casing varies between API Gateway REST and HTTP APIs.
headers = {k.lower(): v for k, v in (event.get("headers") or {}).items()}
supplied = headers.get("x-webhook-secret", "")
if not hmac.compare_digest(supplied, WEBHOOK_SECRET):
return respond(401, {"message": "invalid secret"})
try:
payload = json.loads(event.get("body") or "{}")
except json.JSONDecodeError:
return respond(400, {"message": "body must be JSON"})
# Map your source system's fields here; these match the curl example below.
alert_name = payload.get("alertName", "Unknown alert")
severity = payload.get("severity", "P3")
message = payload.get("message", "")
description = adf_paragraphs(f"Severity: {severity}", message)
description["content"].append(adf_code_block(json.dumps(payload, indent=2)))
issue = {
"fields": {
"project": {"key": JIRA_PROJECT_KEY},
"issuetype": {"name": JIRA_ISSUE_TYPE},
"summary": f"[{severity}] {alert_name}"[:255], # Jira's summary limit
"description": description,
"labels": ["auto-created", f"severity-{severity.lower()}"],
}
}
token = base64.b64encode(f"{JIRA_EMAIL}:{JIRA_API_TOKEN}".encode()).decode()
request = urllib.request.Request(
f"{JIRA_BASE_URL}/rest/api/3/issue",
data=json.dumps(issue).encode(),
method="POST",
headers={
"Authorization": f"Basic {token}",
"Accept": "application/json",
"Content-Type": "application/json",
},
)
try:
with urllib.request.urlopen(request, timeout=10) as resp:
created = json.load(resp)
except urllib.error.HTTPError as err:
# Log Jira's error details, but don't echo them back to the caller.
print(f"Jira API error {err.code}: {err.read().decode()}")
return respond(502, {"message": "failed to create Jira issue"})
print(f"Created {created['key']}")
return respond(201, {"key": created["key"]})Deployment Notes:
- Save the code as
lambda_function.pyand create a Lambda function with a currently supported Python runtime (3.12 or later). - Under Configuration > Environment variables, add:
JIRA_BASE_URL:https://your-domain.atlassian.netJIRA_EMAIL: Your Atlassian account emailJIRA_API_TOKEN: Your generated API tokenJIRA_PROJECT_KEY: E.g.,DEVJIRA_ISSUE_TYPE_NAME: E.g.,BugWEBHOOK_SECRET: A long random string (e.g., fromopenssl rand -hex 32) that the sending system includes in anX-Webhook-Secretheader
- Because the function uses
urllibinstead ofrequests, no extra packages or Lambda layers are needed. - Errors from Jira come back as HTTP 502 to the caller. The detailed Jira response (often a field validation message) goes to CloudWatch Logs.
Step 3: Configure API Gateway as a Webhook Endpoint
- In the AWS Console, navigate to API Gateway. Create a new REST API.
- Create a resource (e.g.,
/jira-webhook). - Create a
POSTmethod under this resource. - For the integration type, select
Lambda Functionand choose your newly created Lambda function. - Enable Use Lambda Proxy integration so the function receives headers and the raw body in
event. - Deploy your API to a stage (e.g.,
prod). The stage's "Invoke URL" is your webhook endpoint.
If you don't need API Gateway features like throttling or custom authorizers, a Lambda function URL is a simpler alternative. The handler works unchanged with the same proxy event format.
Step 4: Configure the External System to Send Webhooks
Now, wherever your events originate, configure them to send an HTTP POST request to your API Gateway Invoke URL. The exact configuration will depend on your external system. For testing, you can use curl:
curl -X POST \
-H "Content-Type: application/json" \
-H "X-Webhook-Secret: $WEBHOOK_SECRET" \
-d '{ "alertName": "Critical Database Latency", "message": "Database latency spiked above 500ms for 5 minutes.", "severity": "P1" }' \
"https://<api-gateway-id>.execute-api.<region>.amazonaws.com/prod/jira-webhook"After executing this, you should get a 201 response with the new issue key, and see an issue titled [P1] Critical Database Latency in the project, with the raw payload in a code block. If Jira rejects the request, CloudWatch Logs shows why. The most common causes are an issue type name that doesn't exist in that project, or a required custom field you haven't set.
⚠️ Common mistake: Sending a plain string as
descriptionto/rest/api/3/issue. The v3 API returns400with "Operation value must be an Atlassian Document". Either build ADF as shown above or use the older/rest/api/2/issueendpoint, which still accepts plain text (wiki markup).
Before Running This in Production
- Deduplicate repeat alerts: Monitoring systems re-fire the same alert. Search for an open issue first (
POST /rest/api/3/search/jqlwith a label or a fingerprint stored in a custom field) and add a comment rather than creating a duplicate. - Move secrets out of environment variables: Store the Jira token and webhook secret in AWS Secrets Manager or SSM Parameter Store, and cache them outside the handler so they're fetched once per container rather than on every call.
- Handle Jira rate limits: Jira Cloud returns
429with aRetry-Afterheader under load. For bursty sources, put an SQS queue between API Gateway and the function so retries don't drop events. - Dynamic Field Mapping: Extend the Lambda to map specific fields from the incoming webhook to different Jira custom fields based on rules or configuration.
- Stronger authentication: If the sending system signs requests (GitHub, Stripe and many monitoring tools send an HMAC signature header), verify that signature instead of a static shared secret.
- Rate Limiting: Use API Gateway's throttling features to protect your Lambda and Jira from excessive requests.
Summary
- Keep the translation logic in one small function: verify the caller, map fields, call Jira.
- Send descriptions to the v3 API as Atlassian Document Format, or use the v2 endpoint for plain text.
- Look up issue type names or IDs per project instead of hard-coding IDs from examples.
- Deduplicate repeat alerts before going to production, or the integration will flood your backlog.
