<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bheem Reddy on Medium]]></title>
        <description><![CDATA[Stories by Bheem Reddy on Medium]]></description>
        <link>https://medium.com/@bheemreddy181?source=rss-d55c783fbd04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fLgcEY5Cc43fcj5p.jpg</url>
            <title>Stories by Bheem Reddy on Medium</title>
            <link>https://medium.com/@bheemreddy181?source=rss-d55c783fbd04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:07:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bheemreddy181/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploying GitHub safe-settings to AWS Lambda: A Docker-First Serverless Approach]]></title>
            <link>https://medium.com/@bheemreddy181/deploying-github-safe-settings-to-aws-lambda-a-docker-first-serverless-approach-d70eff7a0c6b?source=rss-d55c783fbd04------2</link>
            <guid isPermaLink="false">https://medium.com/p/d70eff7a0c6b</guid>
            <category><![CDATA[branch-policies]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Bheem Reddy]]></dc:creator>
            <pubDate>Sat, 02 Aug 2025 04:58:42 GMT</pubDate>
            <atom:updated>2025-08-02T04:58:42.437Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How we transformed a traditional GitHub App into a scalable, cost-effective serverless solution using Docker containers and AWS Lambda</em></p><h3>The Challenge: Making GitHub Apps Serverless</h3><p>GitHub’s <a href="https://github.com/github/safe-settings">Safe Settings</a> is a powerful tool for managing repository configurations at scale. However, running it traditionally requires maintaining always-on servers, which can be costly and complex to manage. What if we could leverage the power of serverless computing while maintaining the full functionality of Safe Settings?</p><p>In this post, I’ll walk you through how we successfully deployed Safe Settings to AWS Lambda using Docker containers, creating a solution that’s both cost-effective and highly scalable.</p><h3>Why Lambda + Docker for GitHub Apps?</h3><h3>The Traditional Approach vs. Serverless</h3><p>Most GitHub Apps run on traditional servers or container orchestration platforms like Kubernetes. While these approaches work, they come with challenges:</p><ul><li><strong>Always-on costs</strong>: You pay for server time even when no webhooks are being processed</li><li><strong>Scaling complexity</strong>: Managing traffic spikes requires sophisticated auto-scaling</li><li><strong>Maintenance overhead</strong>: Server patching, monitoring, and infrastructure management</li></ul><h3>The Lambda Advantage</h3><p>AWS Lambda with container support offers compelling benefits:</p><ul><li><strong>True pay-per-use</strong>: Only pay for actual execution time</li><li><strong>Automatic scaling</strong>: Handle traffic spikes without configuration</li><li><strong>Zero maintenance</strong>: No servers to patch or monitor</li><li><strong>Native container support</strong>: Use existing Docker workflows</li></ul><h3>Architecture Overview</h3><p>Our solution uses a smart dual-function approach with comprehensive event handling and automated deployment. Let’s break down the architecture with visual diagrams:</p><h3>🏗️ High-Level System Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zwwf0YAwOXEcb_bIfv1zg.png" /></figure><p>This architecture provides clear separation between:</p><ul><li><strong>Webhook processing</strong> for real-time GitHub events</li><li><strong>Scheduled synchronization</strong> for periodic repository auditing</li><li><strong>Automated deployment</strong> through GitHub Actions</li><li><strong>Centralized container management</strong> via Amazon ECR</li></ul><h3>🔄 Request Flow Visualization</h3><p>Understanding how different types of requests flow through the system is crucial:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZVFmnP3TpPi5o20Y9cdaA.png" /></figure><p>This dual-mode operation ensures both reactive (webhook-driven) and proactive (scheduled) repository management.</p><h3>Step 1: Understanding the Safe Settings Structure</h3><p>Before adapting any GitHub App for Lambda, it’s crucial to understand its structure. Safe Settings is built on the <a href="https://probot.github.io/">Probot framework</a>, which provides:</p><ul><li>Event-driven architecture perfect for serverless</li><li>Built-in webhook signature validation</li><li>GitHub API authentication handling</li><li>Plugin-based extensibility</li></ul><p>The key insight was that Safe Settings already had the right architectural patterns for Lambda — we just needed to add the right adapter layer.</p><h3>Step 2: Creating the Lambda Adapter</h3><p>The heart of our solution is a smart handler that routes different types of events:</p><pre>// safe-settings-handler.js<br>const { createLambdaFunction } = require(&#39;@probot/adapter-aws-lambda-serverless&#39;);<br>const appFn = require(&#39;./lib/safe-settings&#39;);</pre><pre>// Webhook handler for GitHub events<br>const webhookHandler = createLambdaFunction(appFn, {<br>  probot: {<br>    logLevel: process.env.LOG_LEVEL || &#39;info&#39;,<br>  },<br>});</pre><pre>// Scheduler handler for periodic sync operations<br>async function schedulerHandler(event, context) {<br>  console.log(&#39;Scheduler event received:&#39;, JSON.stringify(event, null, 2));<br>  <br>  // In development, use mock implementation<br>  if (process.env.NODE_ENV === &#39;development&#39; &amp;&amp; !process.env.APP_ID) {<br>    return {<br>      statusCode: 200,<br>      body: JSON.stringify({<br>        message: &#39;Mock scheduler executed successfully&#39;,<br>        timestamp: new Date().toISOString(),<br>        environment: &#39;development&#39;<br>      })<br>    };<br>  }<br>  <br>  // Production sync logic here<br>  // This would integrate with Safe Settings&#39; sync functionality<br>  return {<br>    statusCode: 200,<br>    body: JSON.stringify({<br>      message: &#39;Sync completed successfully&#39;,<br>      timestamp: new Date().toISOString()<br>    })<br>  };<br>}</pre><pre>// Smart routing based on event type<br>exports.webhooks = async (event, context) =&gt; {<br>  try {<br>    return await webhookHandler(event, context);<br>  } catch (error) {<br>    console.error(&#39;Webhook handler error:&#39;, error);<br>    return {<br>      statusCode: 500,<br>      body: JSON.stringify({ error: &#39;Internal server error&#39; })<br>    };<br>  }<br>};</pre><pre>exports.scheduler = async (event, context) =&gt; {<br>  try {<br>    return await schedulerHandler(event, context);<br>  } catch (error) {<br>    console.error(&#39;Scheduler handler error:&#39;, error);<br>    return {<br>      statusCode: 500,<br>      body: JSON.stringify({ error: &#39;Internal server error&#39; })<br>    };<br>  }<br>};</pre><h3>Step 3: Docker Container Strategy</h3><p>We used a multi-stage Docker build to create an optimized Lambda container. Here’s how our container architecture works:</p><h3>🐳 Container Build Strategy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBPrGv0jtRn61JJ-iluJgA.png" /></figure><p>The Dockerfile implementation:</p><pre># Stage 1: Get Safe Settings source<br>FROM ghcr.io/github/safe-settings:2.1.17 AS source</pre><pre># Stage 2: Build Lambda-optimized container<br>FROM public.ecr.aws/lambda/nodejs:20</pre><pre># Copy Safe Settings source code<br>COPY --from=source /opt/safe-settings/ ${LAMBDA_TASK_ROOT}/</pre><pre># Copy our Lambda adapter<br>COPY safe-settings-handler.js ${LAMBDA_TASK_ROOT}/<br>COPY utils/ ${LAMBDA_TASK_ROOT}/utils/</pre><pre># Install Lambda-specific dependencies<br>RUN npm install @probot/adapter-aws-lambda-serverless</pre><pre># Default command (can be overridden per function)<br>CMD [&quot;safe-settings-handler.webhooks&quot;]</pre><p>This approach gives us several advantages:</p><ul><li><strong>Official source</strong>: We use the exact same code as the official Safe Settings</li><li><strong>Minimal additions</strong>: Only add the Lambda adapter layer</li><li><strong>Flexibility</strong>: Same image serves both webhook and scheduler functions</li><li><strong>Updates</strong>: Easy to update to new Safe Settings versions</li></ul><h3>Step 4: Handling Different Event Types</h3><p>One of the trickiest parts was handling the different types of events Lambda might receive. Our handler includes sophisticated routing logic:</p><h3>🔧 Handler Logic Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mt9FuoRP31BONYHTpoMd-A.png" /></figure><h3>Event Types We Handle</h3><h4>GitHub Webhooks</h4><p>These come through the Lambda Function URL and have a specific structure with headers for signature validation.</p><h4>EventBridge Scheduled Events</h4><p>These are triggered by CloudWatch Events/EventBridge for periodic syncing.</p><h4>Manual Invocations</h4><p>These might be triggered manually for testing or administrative tasks.</p><p>Our handler intelligently routes these:</p><pre>// Event routing logic<br>if (event.source === &#39;aws.events&#39; || event.sync === true) {<br>  // Handle scheduled sync<br>  return await schedulerHandler(event, context);<br>}</pre><pre>// Default to webhook handling<br>return await webhookHandler(event, context);</pre><h3>Step 5: CI/CD Pipeline</h3><p>We implemented a comprehensive GitHub Actions pipeline that handles testing, building, and deployment with full automation:</p><h3>🚀 Automated Deployment Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37i2x0CF9CuT_sOOUrzq_g.png" /></figure><h3>Pipeline Implementation</h3><h4>Testing</h4><pre>- name: Run Tests<br>  run: |<br>    npm test<br>    npm run test:coverage</pre><h4>Security</h4><pre>- name: Security Audit<br>  run: npm audit --audit-level high</pre><h4>Docker Build &amp; Deploy</h4><pre>- name: Build and Push to ECR<br>  run: |<br>    docker build -t safe-settings-lambda .<br>    docker tag safe-settings-lambda:latest $ECR_REGISTRY/safe-settings-lambda:latest<br>    docker push $ECR_REGISTRY/safe-settings-lambda:latest</pre><pre>- name: Update Lambda Functions<br>  run: |<br>    aws lambda update-function-code \<br>      --function-name safe-settings-lambda \<br>      --image-uri $ECR_REGISTRY/safe-settings-lambda:latest<br>      <br>    aws lambda update-function-code \<br>      --function-name safe-settings-scheduler \<br>      --image-uri $ECR_REGISTRY/safe-settings-lambda:latest</pre><h3>Step 6: Environment Configuration</h3><p>Lambda functions require careful environment variable management:</p><pre># Core GitHub App credentials<br>APP_ID=your-github-app-id<br>PRIVATE_KEY=your-private-key<br>WEBHOOK_SECRET=your-webhook-secret</pre><pre># Optional OAuth for enhanced functionality<br>GITHUB_CLIENT_ID=your-client-id<br>GITHUB_CLIENT_SECRET=your-client-secret</pre><pre># Operational settings<br>LOG_LEVEL=info<br>NODE_ENV=production</pre><h3>Lessons Learned</h3><h3>1. Container Size Matters</h3><p>Lambda has a 10GB container size limit, but smaller containers start faster. We optimized our image by:</p><ul><li>Using multi-stage builds</li><li>Only copying necessary files</li><li>Leveraging Lambda’s Node.js base images</li></ul><h3>2. Cold Start Optimization</h3><p>To minimize cold starts:</p><ul><li>Keep the container small</li><li>Initialize connections lazily</li><li>Use provisioned concurrency for critical functions</li></ul><h3>3. Error Handling is Critical</h3><p>In serverless environments, errors can be harder to debug:</p><ul><li>Implement comprehensive logging</li><li>Use structured logging (JSON)</li><li>Include request IDs for tracing</li></ul><h3>4. Testing Strategy</h3><p>We implemented multiple testing layers:</p><ul><li>Unit tests for utility functions</li><li>Integration tests for handler logic</li><li>Mock implementations for development</li></ul><h3>Performance and Cost Benefits</h3><p>After deployment, we saw significant improvements:</p><h3>Cost Reduction</h3><ul><li><strong>Before</strong>: $200/month for always-on EC2 instance</li><li><strong>After</strong>: $15/month for typical webhook volume</li><li><strong>Savings</strong>: 92% cost reduction</li></ul><h3>Scalability</h3><ul><li>Handles traffic spikes automatically</li><li>No manual scaling configuration required</li><li>Supports thousands of concurrent webhooks</li></ul><h3>Maintenance</h3><ul><li>Zero server maintenance</li><li>Automatic security updates via base images</li><li>Simplified monitoring through CloudWatch</li></ul><h3>Deployment Guide</h3><p>Here’s a quick start guide for deploying your own instance:</p><h3>1. AWS Setup</h3><pre># Create ECR repository<br>aws ecr create-repository --repository-name safe-settings-lambda</pre><pre># Create Lambda functions<br>aws lambda create-function \<br>  --function-name safe-settings-lambda \<br>  --code ImageUri=YOUR_ACCOUNT.dkr.ecr.REGION.amazonaws.com/safe-settings-lambda:latest \<br>  --role arn:aws:iam::YOUR_ACCOUNT:role/lambda-execution-role \<br>  --package-type Image \<br>  --image-config &#39;{&quot;Command&quot;:[&quot;safe-settings-handler.webhooks&quot;]}&#39;</pre><pre>aws lambda create-function \<br>  --function-name safe-settings-scheduler \<br>  --code ImageUri=YOUR_ACCOUNT.dkr.ecr.REGION.amazonaws.com/safe-settings-lambda:latest \<br>  --role arn:aws:iam::YOUR_ACCOUNT:role/lambda-execution-role \<br>  --package-type Image \<br>  --image-config &#39;{&quot;Command&quot;:[&quot;safe-settings-handler.scheduler&quot;]}&#39;</pre><h3>2. GitHub Configuration</h3><p>Set up these repository secrets:</p><ul><li>AWS_REGION</li><li>APP_ID</li><li>PRIVATE_KEY</li><li>WEBHOOK_SECRET</li></ul><h3>3. Deploy</h3><p>Push to your main branch to trigger the GitHub Actions deployment.</p><h3>Best Practices for GitHub Apps in Lambda</h3><p>Based on our experience, here are key recommendations:</p><h3>1. Use Official Sources</h3><p>Always base your containers on official app sources when possible. This ensures you get security updates and new features automatically.</p><h3>2. Implement Smart Routing</h3><p>Different event types require different handling. Build intelligent routing into your handler.</p><h3>3. Plan for Development</h3><p>Include mock implementations for local testing without external dependencies.</p><h3>4. Monitor Everything</h3><p>Use CloudWatch Logs and Metrics extensively. Serverless applications can be harder to debug.</p><h3>5. Test Thoroughly</h3><p>Implement comprehensive testing including unit tests, integration tests, and end-to-end validation.</p><h3>Future Enhancements</h3><p>We’re planning several improvements:</p><h3>Advanced Scheduling</h3><p>Moving from simple periodic sync to intelligent, event-driven synchronization based on repository activity.</p><h3>Multi-Region Deployment</h3><p>Deploying to multiple AWS regions for better global performance.</p><h3>Enhanced Monitoring</h3><p>Implementing custom CloudWatch metrics and alarms for better operational visibility.</p><h3>Cost Optimization</h3><p>Using Lambda’s new pricing models and provisioned concurrency strategically.</p><h3>Conclusion</h3><p>Deploying Safe Settings to AWS Lambda using Docker containers proved to be an excellent architectural choice. We achieved:</p><ul><li><strong>92% cost reduction</strong> compared to traditional hosting</li><li><strong>Zero maintenance overhead</strong> for infrastructure</li><li><strong>Automatic scaling</strong> for traffic spikes</li><li><strong>Improved reliability</strong> through managed services</li></ul><p>The key insights that made this successful were:</p><ol><li><strong>Leverage existing architecture</strong>: Safe Settings’ event-driven design was perfect for Lambda</li><li><strong>Use official sources</strong>: Building on the official Safe Settings container ensured compatibility</li><li><strong>Implement smart routing</strong>: Different event types need different handling strategies</li><li><strong>Invest in testing</strong>: Comprehensive testing is crucial for serverless applications</li><li><strong>Monitor extensively</strong>: Good observability is essential for debugging serverless apps</li></ol><p>This approach can be applied to many other GitHub Apps and similar event-driven applications. The combination of Docker containers and Lambda provides the flexibility of traditional deployments with the benefits of serverless computing.</p><p>Whether you’re running Safe Settings or another GitHub App, consider the serverless approach — the cost savings and operational simplicity might surprise you.</p><h3>Acknowledgments</h3><p>Special thanks to <a href="https://www.linkedin.com/in/bennettbrucew/">Bruce Bennett</a> for his invaluable guidance and collaboration on the architectural design and implementation strategy that made this serverless transformation possible. His insights on containerization patterns and Lambda optimization were instrumental in achieving the performance and cost benefits outlined in this post.</p><p><em>Have questions about deploying GitHub Apps to Lambda? Found this helpful? Let me know in the comments below!</em></p><h3>Resources</h3><ul><li><a href="https://github.com/github/safe-settings">GitHub Safe Settings Repository</a></li><li><a href="https://probot.github.io/">Probot Framework Documentation</a></li><li><a href="https://docs.aws.amazon.com/lambda/latest/dg/images-create.html">AWS Lambda Container Image Support</a></li><li><a href="https://github.com/your-org/safe-settings-lambda">Complete Source Code</a> <em>(replace with your actual repo)</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d70eff7a0c6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>