Template Content
About the template
About ScriptRunner Connect
What is ScriptRunner Connect?
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
This template makes a copy of an attachment in AWS S3 when a new attachment is added to Jira Cloud issue.
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.
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;
}