<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kro</title>
    <description>The latest articles on DEV Community by Kro (@kro12).</description>
    <link>https://dev.to/kro12</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F336291%2Fe353ad0e-ff24-4816-a24a-db675e1d143c.jpeg</url>
      <title>DEV Community: Kro</title>
      <link>https://dev.to/kro12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kro12"/>
    <language>en</language>
    <item>
      <title>Automatically transition Jira issues using a Github webhook</title>
      <dc:creator>Kro</dc:creator>
      <pubDate>Sat, 22 Feb 2020 02:08:43 +0000</pubDate>
      <link>https://dev.to/kro12/automatically-transition-jira-issues-using-a-github-webhook-2i75</link>
      <guid>https://dev.to/kro12/automatically-transition-jira-issues-using-a-github-webhook-2i75</guid>
      <description>&lt;h1&gt;
  
  
  What's this all about eh?
&lt;/h1&gt;

&lt;p&gt;One of the perks of my job is that on the last Friday of every month we get to work on our hack of choice, as long as it is in some way work related - &lt;a href="https://stitcherads.com/careers/" rel="noopener noreferrer"&gt;come join us 👋&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We use Github for our repos and Jira for project management. This pairing offers some nice functionality through the use of third-party addons such as &lt;a href="https://marketplace.atlassian.com/apps/1219592/github-for-jira" rel="noopener noreferrer"&gt;GitHub for Jira&lt;/a&gt; which allow us to add pull request context to Jira issues.&lt;/p&gt;

&lt;p&gt;Jira supports many workflow transitions out-of-the-box including the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Pull Request created&lt;/li&gt;
&lt;li&gt;  Branch created&lt;/li&gt;
&lt;li&gt;  Commit created&lt;/li&gt;
&lt;li&gt;  Review rejected
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the full list at &lt;a href="https://confluence.atlassian.com/adminjiracloud/available-workflow-triggers-for-classic-projects-973489424.html" rel="noopener noreferrer"&gt;confluence.atlassian.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Work Setup 💻
&lt;/h2&gt;

&lt;p&gt;Our Jira Workflows are quite involved but for us developers our primary focus is on the following Jira workflow transition states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  In Development&lt;/li&gt;
&lt;li&gt;  Ready for UI review&lt;/li&gt;
&lt;li&gt;  Ready for review (Dev)&lt;/li&gt;
&lt;li&gt;  Ready for QA&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As part of a busy team there’s the inevitable context switching and we have many responsibilities including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Performing due diligence on new functionality&lt;/li&gt;
&lt;li&gt;  PR reviews within our team&lt;/li&gt;
&lt;li&gt;  Feature planning and development&lt;/li&gt;
&lt;li&gt;  Bug fixing&lt;/li&gt;
&lt;li&gt;  Mentoring&lt;/li&gt;
&lt;li&gt;  etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once our PRs have passed &lt;em&gt;UI approval&lt;/em&gt; we then assign two &lt;em&gt;Dev reviewers&lt;/em&gt; from within our team and transition the Jira ticket to &lt;em&gt;Ready for review&lt;/em&gt;.&lt;br&gt;
Reviews can take time for many reasons including the size of the feature, the amount of feedback, changes requested, and the number of PRs we have on the go at a given point in time; it can be difficult to notice when one has been granted the required number of approving Dev reviews and to manually then move the associated Jira ticket to the next stage in the workflow (&lt;a href="https://pullreminders.com/" rel="noopener noreferrer"&gt;Pull Panda&lt;/a&gt; &lt;em&gt;can be hugely beneficial in this area, it's a must-have for any large team&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;For this reason tickets don’t always get moved on to &lt;em&gt;Ready for QA&lt;/em&gt; in a timely manner and this can lead to completed pieces of functionality not becoming visible to our QA team, having the knock on effect of delaying its ultimate release.&lt;/p&gt;

&lt;p&gt;As a developer my instinct was to look at somehow automating this process. I initially investigated if Jira offered support for a &lt;em&gt;PR Approved&lt;/em&gt; transition, but unfortunately this led me down a black hole as the following public Jira request hilights -  &lt;a href="https://jira.atlassian.com/browse/JRACLOUD-71798" rel="noopener noreferrer"&gt;https://jira.atlassian.com/browse/JRACLOUD-71798&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3zx3ntejtthtxfs78flu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3zx3ntejtthtxfs78flu.png" alt="approved trigger ticket"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdt35ajer5zjmswb7trjg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdt35ajer5zjmswb7trjg.jpg" alt="lost-in-space"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After giving this more thought it also became apparent that should this be supported by Jira in the future, it wouldn’t suffice as I would also need to apply some additional business-logic once a &lt;em&gt;PR approval&lt;/em&gt; was received.  &lt;/p&gt;
&lt;h2&gt;
  
  
  So What Now? 🕵️
&lt;/h2&gt;

&lt;p&gt;I set about coming up with a loose plan of action which would enable me to create a proof of concept. At this stage I had a rough idea of the pieces of the puzzle which I would need to combine to achieve my end goal, these included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Github’s Webhook support&lt;/li&gt;
&lt;li&gt;  Github’s REST API&lt;/li&gt;
&lt;li&gt;  JIRA’s REST API&lt;/li&gt;
&lt;li&gt;Serverless backend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2Fc%2Fc0%2FPortal_physics-2.svg%2F1129px-Portal_physics-2.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2Fc%2Fc0%2FPortal_physics-2.svg%2F1129px-Portal_physics-2.svg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github provides an exhaustive list of supported webhook events but the one that appeared to best suit my needs was&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pull request reviews - review submitted, edited or dismissed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The payload from this event provides us with useful details including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Action - &lt;em&gt;submitted, edited, dismissed&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  Review and &lt;em&gt;reviewer details&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  Details of the pull request including &lt;em&gt;link, creator, etc&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further details can be found in the &lt;a href="https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent" rel="noopener noreferrer"&gt;Github docs&lt;/a&gt; along with sample payloads. &lt;/p&gt;
&lt;h2&gt;
  
  
  Are We Missing Anything? 🔍
&lt;/h2&gt;

&lt;p&gt;It quickly became apparent to me that I would need to make subsequent requests against the &lt;em&gt;Github REST API&lt;/em&gt; to retrieve all other associated reviews; this additional info would allow me to do the processing required to consider the Jira ticket ready for transition.&lt;/p&gt;

&lt;p&gt;At this point I had the following mental model in my head:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Github review webhook fires&lt;/li&gt;
&lt;li&gt;  Parse review and if approval then proceed&lt;/li&gt;
&lt;li&gt;  Fetch additional PR reviews (&lt;em&gt;Github REST API&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;  Parse reviews only counting latest per user and those that are approvals&lt;/li&gt;
&lt;li&gt;  If two or more approving Dev reviews then transition associated issue (&lt;em&gt;Jira REST API&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;  Notify the pull request creator via Slack (&lt;em&gt;also surface any errors which might occur&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthumbs.dreamstime.com%2Fm%2Flogotype-brain-silhouette-rain-cloud-inside-human-black-big-small-drops-lightning-isolated-vector-illustration-93842982.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthumbs.dreamstime.com%2Fm%2Flogotype-brain-silhouette-rain-cloud-inside-human-black-big-small-drops-lightning-isolated-vector-illustration-93842982.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that I had a plan in place the next step was to choose how I would process the Webhook request and make the necessary requests to &lt;em&gt;Github&lt;/em&gt;, &lt;em&gt;Jira&lt;/em&gt; and &lt;em&gt;Slack&lt;/em&gt;.&lt;br&gt;
I’ve worked with Amazon’s Lambda functions in the past and knew that if I combined this with an Amazon API Gateway it could be a good fit for this project.&lt;/p&gt;

&lt;p&gt;To avoid overcomplicating this article I’m going to generate the Lambda function inline using the provided editor, relying on the following natively supported packages for request processing - &lt;em&gt;crypto&lt;/em&gt;, &lt;em&gt;https&lt;/em&gt; and &lt;em&gt;url&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
I've also decided not to cover setting up the Slack API and the associated webhook in the interest of brevity (&lt;em&gt;if this is something you would like me to cover then please let me know&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;As this was to be run on the companies &lt;em&gt;Github&lt;/em&gt;, &lt;em&gt;Jira&lt;/em&gt;, &lt;em&gt;AWS&lt;/em&gt; accounts I also wanted to focus on ensuring the project was secure despite the fact that it would be a POC.&lt;/p&gt;

&lt;p&gt;For this purpose I added the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Included an optional &lt;em&gt;secret&lt;/em&gt; with the Github webhook payload which would be validated&lt;/li&gt;
&lt;li&gt;  Configured the API Gateway to validate the presence of the following headers

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;X-GitHub-Delivery&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;X-Hub-Signature&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;  Store all required tokens (&lt;em&gt;API tokens, etc.&lt;/em&gt;) in Amazon &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html" rel="noopener noreferrer"&gt;Parameters Store&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Set up an IAM role providing the Lambda with access to only the parameters it required by leveraging &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetParameters.html" rel="noopener noreferrer"&gt;ssm:GetParameters&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Okay, enough talk, let's get down to business!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pixabay.com%2Fphoto%2F2016%2F03%2F31%2F18%2F16%2Fattack-1294254_960_720.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pixabay.com%2Fphoto%2F2016%2F03%2F31%2F18%2F16%2Fattack-1294254_960_720.png" alt="Image result for attack"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;I’ve organised the technical overview into the following sections:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Setting up the Lambda function&lt;/li&gt;
&lt;li&gt; Creating the API Gateway - configuring the endpoint - forwarding the payload to the Lambda function - verifying the request headers&lt;/li&gt;
&lt;li&gt;Setting up the Github Webhook &lt;/li&gt;
&lt;li&gt; Storing the sensitive parameters using the &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html" rel="noopener noreferrer"&gt;Parameter Store&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Generating the Lambda function role - configuring this role to only have access to the specific parameters required&lt;/li&gt;
&lt;li&gt; Adding the control logic to our Lambda function - &lt;del&gt;testing our Lambda function&lt;/del&gt;
&lt;/li&gt;
&lt;li&gt; Areas where we could improve the functionality&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  1) Setting up the Lambda function 👨‍💻
&lt;/h2&gt;

&lt;p&gt;Log into AWS and choose the Lambda service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FwYrqlM9jVZJfu2APaRcKn0PK0gagc6Mh-o1gUEUDK_kw1FYfHZsl_z4W8obMzEUtmmqdZD17HLn413XsokzRVByhonKcmC7_K2hxuKydubG0ianpJkwz0YkBK1fFnbjuzzGQ6ZeX" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FwYrqlM9jVZJfu2APaRcKn0PK0gagc6Mh-o1gUEUDK_kw1FYfHZsl_z4W8obMzEUtmmqdZD17HLn413XsokzRVByhonKcmC7_K2hxuKydubG0ianpJkwz0YkBK1fFnbjuzzGQ6ZeX" alt="lambda service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;from here choose '&lt;strong&gt;&lt;em&gt;Create function&lt;/em&gt;&lt;/strong&gt;'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0o0nhyexuyy135b011ac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0o0nhyexuyy135b011ac.png" alt="create lambda function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next choose ‘&lt;strong&gt;&lt;em&gt;Author from scratch&lt;/em&gt;&lt;/strong&gt;’ and give your function a meaningful name. I went with the default runtime and chose ‘&lt;strong&gt;&lt;em&gt;Create a new role with basic Lambda permissions&lt;/em&gt;&lt;/strong&gt;’.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FgkuaxGLgyxDNVMP9QQGkOcESJzw9-ir5KQfBo8txTYaSmLrDb0dBW73DrOmgSEhG_R7TrpfZj6NGnl4LcdMyfKOfegs52jATFd3u08yEJB3rIRC_ZVJHMevBvI7Bp4-AeE7YCU7W" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FgkuaxGLgyxDNVMP9QQGkOcESJzw9-ir5KQfBo8txTYaSmLrDb0dBW73DrOmgSEhG_R7TrpfZj6NGnl4LcdMyfKOfegs52jATFd3u08yEJB3rIRC_ZVJHMevBvI7Bp4-AeE7YCU7W" alt="author lambda  from scratch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once created we now have a &lt;em&gt;placeholder Lambda function&lt;/em&gt; that we can refer to when setting up our &lt;em&gt;API Gateway&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  2) Setting up the API Gateway 🛣️
&lt;/h2&gt;

&lt;p&gt;Choose API gateway from the Services menu.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh6.googleusercontent.com%2F_8_-qYLXDKLKa1a2kbvdbtizk5hLEytnvFxvOjCYz6CRgDe-BmYKR6CNxpjuRZbuL5eT0bjpl5moc9oBOhoTXaqQvZ6s1dMczmGUx0dS7L_ry0IrIT_pqSoeX4-BddpCSUpX8ddn" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh6.googleusercontent.com%2F_8_-qYLXDKLKa1a2kbvdbtizk5hLEytnvFxvOjCYz6CRgDe-BmYKR6CNxpjuRZbuL5eT0bjpl5moc9oBOhoTXaqQvZ6s1dMczmGUx0dS7L_ry0IrIT_pqSoeX4-BddpCSUpX8ddn" alt="api gateway"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I initially tried creating a &lt;em&gt;HTTP API (Beta) Gateway&lt;/em&gt; but ran into some issues so switched to an &lt;em&gt;externally accessible REST API&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FF40pNZXzrO7bQDG5lk_v9mdgUbQkHUEsCeVRLwutfWySyokwYNhFWOFanZLZRGCJ-j09wLPO9mW2X_1Q-o1R4tbViBx3tcBXDTZGp4ZW6i32im9kcWhpO-cEJHC0kFRNtjpisyfo" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh3.googleusercontent.com%2FF40pNZXzrO7bQDG5lk_v9mdgUbQkHUEsCeVRLwutfWySyokwYNhFWOFanZLZRGCJ-j09wLPO9mW2X_1Q-o1R4tbViBx3tcBXDTZGp4ZW6i32im9kcWhpO-cEJHC0kFRNtjpisyfo" alt="rest api"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Fill in a &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;description&lt;/em&gt; and continue with the defaults to generate a new REST API.&lt;/p&gt;

&lt;p&gt;Once the gateway is created we can add a resource and further configure our endpoint.&lt;br&gt;
Choose the ‘&lt;strong&gt;&lt;em&gt;Actions&lt;/em&gt;&lt;/strong&gt;’ dropdown and select ‘&lt;strong&gt;&lt;em&gt;Create Resource&lt;/em&gt;&lt;/strong&gt;’, giving the new endpoint a meaningful name and path.  &lt;/p&gt;

&lt;p&gt;With our resource selected we then choose ‘&lt;strong&gt;&lt;em&gt;Create method&lt;/em&gt;&lt;/strong&gt;’ from the dropdown and select &lt;strong&gt;&lt;em&gt;POST&lt;/em&gt;&lt;/strong&gt;. This then allows us to choose our Lambda function as the integration for our endpoint.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg63ft6irqn00rm8mxqpm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg63ft6irqn00rm8mxqpm.png" alt="gateway setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next click on the ‘&lt;strong&gt;&lt;em&gt;Method Request&lt;/em&gt;&lt;/strong&gt;’ header to further configure the endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuo08efaiawt6z4ytzdb9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuo08efaiawt6z4ytzdb9.png" alt="gateway config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can then expand the ‘&lt;strong&gt;&lt;em&gt;HTTP Request Headers&lt;/em&gt;&lt;/strong&gt;’ section and add the following as required headers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh4.googleusercontent.com%2F-i6JC3y9W5oCsh0Mf1jaxWms95E7MtXf9EIw_PBXKKNT6-xD0qN2WwlocAur2EvYnJw0ATZnX34hAPkQE5rKERvVlbDFem2Kf9BEyphfcaKVPH8IigkULIynqtkHSjyJTA6V2qyd" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh4.googleusercontent.com%2F-i6JC3y9W5oCsh0Mf1jaxWms95E7MtXf9EIw_PBXKKNT6-xD0qN2WwlocAur2EvYnJw0ATZnX34hAPkQE5rKERvVlbDFem2Kf9BEyphfcaKVPH8IigkULIynqtkHSjyJTA6V2qyd" alt="http request headers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s one final step required which can easily be overlooked. Before we can access our endpoint we first need to activate it.&lt;br&gt;
We do this by choosing ‘&lt;strong&gt;&lt;em&gt;Deploy&lt;/em&gt;&lt;/strong&gt;’ from the ‘&lt;strong&gt;&lt;em&gt;Actions&lt;/em&gt;&lt;/strong&gt;’ drop down menu. Give the deployment a name and hit deploy!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FbKnEnd65zqxfq%2Fgiphy.gif%3Fcid%3D790b7611e9a80e3a09a458525dc6376aba1181dcf81bf16f%26rid%3Dgiphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FbKnEnd65zqxfq%2Fgiphy.gif%3Fcid%3D790b7611e9a80e3a09a458525dc6376aba1181dcf81bf16f%26rid%3Dgiphy.gif" alt="make it so star trek GIF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally grab the ‘&lt;strong&gt;&lt;em&gt;invoke url&lt;/em&gt;&lt;/strong&gt;’ which we will use when setting up our webhook.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh6.googleusercontent.com%2FGPL0VP_eTN2DPrZGnfvAKrqKIr-EUUwbxF8pNSFIndJgG0pK4y406qsqX5Owf-dkRZMcrVt8F0bwqYKLheKatw5b0r7KQ_A-kf-JSewXAyI4Rz9_DHwImplUc7Y7whhQyz-kLMb8" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh6.googleusercontent.com%2FGPL0VP_eTN2DPrZGnfvAKrqKIr-EUUwbxF8pNSFIndJgG0pK4y406qsqX5Owf-dkRZMcrVt8F0bwqYKLheKatw5b0r7KQ_A-kf-JSewXAyI4Rz9_DHwImplUc7Y7whhQyz-kLMb8" alt="invoke url"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;With our &lt;em&gt;Lambda function&lt;/em&gt; and &lt;em&gt;API Gateway&lt;/em&gt; in place we can move on to setting up our &lt;em&gt;Github Webhook&lt;/em&gt;.  &lt;/p&gt;
&lt;h2&gt;
  
  
  3) Setting up the Github Webhook 🕸️
&lt;/h2&gt;

&lt;p&gt;Create a new Webhook for your repo at the following url:&lt;br&gt;
&lt;code&gt;https://github.com/{your organisation}/{your app}/settings/hooks&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3q6zmedne3jmxm4o0cya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3q6zmedne3jmxm4o0cya.png" alt="webhook config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We will configure it as follows:&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Payload URL:&lt;/em&gt;&lt;/strong&gt; the invoke url from the API Gateway we created in the previous section.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Secret:&lt;/em&gt;&lt;/strong&gt; choose to include a secret and give it a value (store this value as we will use it later).&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Content type:&lt;/em&gt;&lt;/strong&gt; application/json&lt;br&gt;
&lt;strong&gt;&lt;em&gt;SSL verification:&lt;/em&gt;&lt;/strong&gt; enabled&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Events:&lt;/em&gt;&lt;/strong&gt; choose ‘&lt;strong&gt;&lt;em&gt;let me select the individual events&lt;/em&gt;&lt;/strong&gt;’ &amp;gt; ‘&lt;strong&gt;&lt;em&gt;Pull request reviews&lt;/em&gt;&lt;/strong&gt;’&lt;br&gt;
Finally choose to activate the webhook.  &lt;/p&gt;

&lt;p&gt;ℹ️ &lt;em&gt;Github provides the handy option of sending a test payload if we want to validate that our endpoint is working as expected. It also logs all webhook requests, even allowing us to replay previous payloads which can be very helpful.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4) Storing the sensitive parameters using the Parameter Store 🤫
&lt;/h2&gt;

&lt;p&gt;Amazon's blurb&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;AWS Systems Manager Parameter Store provides secure, hierarchical&lt;br&gt;
storage for configuration data management and secrets management. You&lt;br&gt;
can store data such as passwords, database strings, and license codes&lt;br&gt;
as parameter values. You can store values as plaintext (unencrypted&lt;br&gt;
data) or ciphertext (encrypted data). You can then reference values by&lt;br&gt;
using the unique name that you specified when you created the&lt;br&gt;
parameter. Highly scalable, available, and durable, Parameter Store is&lt;br&gt;
backed by the AWS Cloud.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'm not going to go into any detail on setting up the parameters as it's pretty self-explanatory.&lt;br&gt;
My advice would be to ensure you name them sensibly and I added a &lt;em&gt;tag&lt;/em&gt; value to each defining the common project.&lt;br&gt;
I've utilised the Store to securely maintain the various API tokens required for this project:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4lw0qkhz1zlnn835rdtx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4lw0qkhz1zlnn835rdtx.png" alt="parameter store listing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;your-github-rest-api-token-param-name&lt;/strong&gt; - token required for REST requests&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;your-github-webhook-secret-param-name&lt;/strong&gt; - webhook has been configured to include a secret in the Headers - '&lt;em&gt;X-Hub-Signature&lt;/em&gt;'&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;your-jira-api-user-param-name&lt;/strong&gt; - REST API creds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;your-jira-api-token-param-name&lt;/strong&gt; - REST API creds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;your-slack-api-token-param-name&lt;/strong&gt; - App webhook token for messaging&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;your-github-dev-reviewer-ids-param-name&lt;/strong&gt; - list of comma separated &lt;em&gt;Github Dev user ids&lt;/em&gt; &lt;em&gt;(I could have simply declared this as a const in the Lambda&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Utilising these in the Lambda function wasn't as straight forward as I had hoped and admittedly my final solution just felt a little contrived &lt;em&gt;(if you know a better way please let me know!)&lt;/em&gt;. That said, it feels a lot more secure than defining them inline in the code or setting then in the functions env variables. The fact that they can be shared between projects and we have a single source of truth is also an added bonus.&lt;/p&gt;

&lt;p&gt;The following code hilights how I retrieved these in the Lambda function:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Initial setup:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="c1"&gt;// require the sdk&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aws-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eu-west-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// create a new SSM instance&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parameterStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SSM&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;// List of the names of the parameters defined in the Parameter Store&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;REQUIRED_PARAMS&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-github-rest-api-token-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-github-webhook-secret-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-github-dev-reviewer-ids-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-jira-api-user-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-jira-api-token-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-slack-api-token-param-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Helper function to make the getParameters request&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getParams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;parameterStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getParameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;Names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;WithDecryption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fetch the parameters and store them in State&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pull the required values from the Parameter Store and store them in State&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;retrievedParams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;REQUIRED_PARAMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Push these into State for later use&lt;/span&gt;
&lt;span class="nx"&gt;REQUIRED_PARAMS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;retrievedParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Parameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;Value&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5) Generating the Lambda function role 🔐
&lt;/h2&gt;

&lt;p&gt;We created our Lambda with a default role. In order for it to be able to access the parameters defined in the previous section we need to update this role to support &lt;em&gt;getParameters&lt;/em&gt; and we will also individually define the parameters that it will be able to access.&lt;/p&gt;

&lt;p&gt;To do this we begin by choosing to view the existing role via the Lambda function &lt;em&gt;Configuration&lt;/em&gt; view. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgfblh7lqmj8qd4rzz2ys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgfblh7lqmj8qd4rzz2ys.png" alt="lambda execution role"&gt;&lt;/a&gt;&lt;br&gt;
From the role view choose &lt;strong&gt;&lt;em&gt;+ add inline policy&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Use the UI to add the following configuration:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3D8HVwTuXd4f0nGAAhFZDkOlgcLZLujX" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3D8HVwTuXd4f0nGAAhFZDkOlgcLZLujX"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Individually add &lt;em&gt;ARN parameters&lt;/em&gt; (&lt;em&gt;or generate the first and then *copy paste and tweak&lt;/em&gt; under &lt;strong&gt;&lt;em&gt;list ARNs manually&lt;/em&gt;&lt;/strong&gt;*)&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3D8rKvGUKMT7NR66Jey7mWEO575A0RaR" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3D8rKvGUKMT7NR66Jey7mWEO575A0RaR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fat5ffom6oxombds609rh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fat5ffom6oxombds609rh.png" alt="lambda role param access"&gt;&lt;/a&gt;&lt;br&gt;
its JSON representation should look like this when you're done:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VisualEditor0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ssm:GetParameters"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-github-webhook-secret-param-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-github-rest-api-token-param-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-github-dev-reviewer-ids-param-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-jira-api-user-param-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-jira-api-token-param-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ssm:your-region-1:your-account-id:parameter/your-slack-api-token-param-name"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the role has been configured and updated your Lambda function will have access to the parameters 👍&lt;/p&gt;

&lt;h2&gt;
  
  
  6) Lambda function control logic 🧠
&lt;/h2&gt;

&lt;p&gt;The logic can be found &lt;a href="http://bit.ly/lambda-handler" rel="noopener noreferrer"&gt;here&lt;/a&gt; 🚀&lt;br&gt;
🍄If you've made it this far please show your appreciation by ⭐'n the repo.&lt;/p&gt;

&lt;p&gt;For the most part I hope the code is pretty self explanatory and I've added plenty of comments. The file is rather large at over &lt;em&gt;300 LOC&lt;/em&gt; but for simplicity I've kept everything in the &lt;em&gt;lambda-handler.js&lt;/em&gt; file. &lt;br&gt;
It's laid out with requires at the top, then helper methods and the main function that receives the request payload from the Gateway is &lt;strong&gt;&lt;em&gt;exports.handler&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;🎉&lt;strong&gt;&lt;em&gt;...and now for the end result...&lt;/em&gt;&lt;/strong&gt;  🎉&lt;/p&gt;

&lt;p&gt;This is what it looks like when the notification comes into&lt;br&gt;
the Slack channel 👀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3DfS8u4Q2F3tjGpaOczOhAtQOmZ10tJn" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fapi.monosnap.com%2Ffile%2Fdownload%3Fid%3DfS8u4Q2F3tjGpaOczOhAtQOmZ10tJn"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/9tzXBdylmxKve/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/9tzXBdylmxKve/giphy.gif" alt="Happy Jeff Bridges GIF"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  7) Room for Improvement 🧽✨
&lt;/h2&gt;

&lt;p&gt;As this was a proof of concept and I haven't had a lot of time to revise the code don't judge me! 🙈😃&lt;/p&gt;

&lt;p&gt;There's certainly room for improvement here.&lt;br&gt;
It would be nice to split the logic out, e.g.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lambda which handles Github requests&lt;/li&gt;
&lt;li&gt;Lambda which handles sending Slack messages&lt;/li&gt;
&lt;li&gt;Lambda which handles Jira requests&lt;/li&gt;
&lt;li&gt;Query Jira to ensure ticket can be transitioned before making the transition request&lt;/li&gt;
&lt;li&gt;etc...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the caveats with the current implementation include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fixed to 2 dev reviews for transition (&lt;em&gt;this could potentially be configured per team as we can grab the team prefix from the Jira issue&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;It will use the first Jira ticket id it finds in the body. This may not always work as one or more additional Jira tickets could also be listed in the PR body. We could mitigate against this by having a predefined character sequence in our PR template which would denote the beginning of the ticket id&lt;/li&gt;
&lt;li&gt;We could potentially support transitioning multiple tickets as some PRs could contain multiple tickets - again we would need to define a way of denoting this in the body, e.g. support an Array of ids - &lt;em&gt;[AT-123, AT-456]&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools used to create this write-up:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://stackedit.io/" rel="noopener noreferrer"&gt;stackedit.io&lt;/a&gt; invaluable in-browser Markdown editor ✅ &lt;br&gt;
&lt;a href="https://pixlr.com/" rel="noopener noreferrer"&gt;pixlr.com&lt;/a&gt; fantastic in-browser image editor (&lt;em&gt;used to create cover image&lt;/em&gt;) ✅&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://open.spotify.com/embed/track/1DLRkp0qE8cui1o94OcOCx" width="100%" height="80px"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>lambda</category>
      <category>github</category>
      <category>jira</category>
      <category>slack</category>
    </item>
  </channel>
</rss>
