When Jira Cloud attachment is added copy it to AWS S3


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how to make a copy of an attachment and store it in AWS S3 when a new attachment is added to Jira Cloud issue. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnJiraCloudAttachmentCreated
Attachment Created

README


๐Ÿ“‹ Overview

This template makes a copy of an attachment in AWS S3 when a new attachment is added to Jira Cloud issue.

๐Ÿ–Š๏ธ Setup

  1. Set up the API connections and event listener: Create connectors for Jira Cloud and AWS, or use existing ones.
  2. Go to Parameters and configure values for AWS region and S3 bucket name.

๐Ÿš€ Usaging the template

When you upload a new issue into Jira Cloud, a copy of the attachment will be stored in AWS S3's bucket you specified. Attachment ID will be used as the S3 object key. When downloaded, S3 will add the original file extension to the attachment ID.

API Connections


TypeScriptOnJiraCloudAttachmentCreated

import Aws from './api/aws';
import JiraCloud from './api/jira/cloud';
import { IssueAttachmentCreatedEvent } from '@sr-connect/jira-cloud/events';

/**
 * When triggered this function will download the attachment content based on the IssueAttachmentCreatedEvent event and will then upload the attachment to S3 with the attachment ID as the S3 object key.
 *
 * @param event Object that holds Attachment Created event data
 * @param context Object that holds function invocation context data
 */
export default async function (event: IssueAttachmentCreatedEvent, context: Context): Promise<void> {
    const params = context.environment.vars as Params;

    console.log(`Getting metadata for attachment: ${event.attachment.id}`);
    const metadata = await JiraCloud.Issue.Attachment.Metadata.getMetadata({
        id: event.attachment.id
    });

    console.log('Downloading attachment content');
    const response = await JiraCloud.fetch(metadata.content ?? '');

    if (!response.ok) {
        throw Error(`Unexpected response while downloading attachment: ${response.status} - ${await response.text()}`);
    }

    const attachmentContent = await response.arrayBuffer();
    const s3ObjectKey = event.attachment.id;

    console.log('Uploading attachment to S3');
    await Aws.S3.Object.putObject({
        bucket: params.AWS_S3_BUCKET_NAME,
        key: s3ObjectKey,
        body: attachmentContent,
        region: params.AWS_REGION
    });

    console.log(`Attachment uploaded to S3 with key: ${s3ObjectKey}`);
}

interface Params {
    readonly AWS_REGION: string;
    readonly AWS_S3_BUCKET_NAME: string;
}
Documentation ยท Support ยท Suggestions & feature requests