<?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 Sandeep Yadav on Medium]]></title>
        <description><![CDATA[Stories by Sandeep Yadav on Medium]]></description>
        <link>https://medium.com/@awsyadav?source=rss-5e4b71f714d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*jlkq0DDUJ-s4LugOAZS16w.jpeg</url>
            <title>Stories by Sandeep Yadav on Medium</title>
            <link>https://medium.com/@awsyadav?source=rss-5e4b71f714d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 13:57:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@awsyadav/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[We Skipped the $50K Firewall. Here’s What We Built Instead.]]></title>
            <link>https://medium.com/@awsyadav/we-skipped-the-50k-firewall-heres-what-we-built-instead-014d5027efba?source=rss-5e4b71f714d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/014d5027efba</guid>
            <category><![CDATA[aws-dns-firewall]]></category>
            <category><![CDATA[zero-trust-security]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[network-security]]></category>
            <category><![CDATA[aws-guardduty]]></category>
            <dc:creator><![CDATA[Sandeep Yadav]]></dc:creator>
            <pubDate>Fri, 10 Apr 2026 07:44:37 GMT</pubDate>
            <atom:updated>2026-04-10T07:44:37.952Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to be upfront about something before this gets technical.</p><p>This is not a “look how smart we are” post. We made plenty of mistakes along the way. We over-engineered things. We bought tools we did not need. We ran a bastion host for two years that nobody patched properly and that kept us up at night every time a new SSH vulnerability dropped.</p><p>What I am sharing here is where we landed after all of that — and why we think it is the right answer for most teams building on AWS.</p><h3>The Problem We Were Actually Trying to Solve</h3><p>We had three things keeping our security team uncomfortable:</p><p>1- Every single DNS query leaving our cloud environment was flying out completely uninspected. If one of our EC2 instances tried to reach a known malware command-and-control server, our network would wave it through without a second thought.</p><p>2- All top-level cybercrime domains were fully reachable from our cloud servers. Phishing infrastructure, botnet endpoints, cryptomining callbacks — accessible, invisible, logged nowhere.</p><p>3- And as we grew — more AWS accounts, more VPCs, more teams — the blast radius of that blind spot grew with it. One misconfigured instance in any spoke could reach anything on the internet and we would not know until something bad happened.</p><p>The traditional answer from every vendor we spoke to was the same: buy a <strong>next-generation firewall.</strong> Deploy an NGFW appliance. Invest in deep packet inspection. The quotes ranged from uncomfortable to genuinely alarming.</p><p>We asked a different question instead.</p><h3>What Does Our Environment Actually Look Like</h3><p>Before the tools make sense, the context matters.</p><p>We run a hub-and-spoke model across multiple AWS accounts under a single AWS Organisation. All outbound internet traffic routes through a central hub VPC — one place to inspect, one place to log, one place to update rules. Spoke VPCs connect through Transit Gateway and inherit security controls via AWS RAM. We have around 50 users who need access to internal systems.</p><p>This model was a deliberate choice. It means we configure security once and it covers everything. When we update a DNS Firewall rule, it propagates to every VPC automatically. When we block an IOC domain, every account is protected within minutes.</p><p>The hub is where security lives. The spokes just get work done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/0*q_xpGE79b8FeuzO3" /></figure><h3>The Stack We Actually Run</h3><h3>Cloudflare — everything internet-facing, all free</h3><p>We use Cloudflare’s free tier for the user-facing edge. Up to 50 users, genuinely enterprise-grade capabilities, zero cost.</p><p><strong>Zero Trust Access instead of VPN</strong></p><p>We have not run a VPN server in over a year. Every internal application is published through Cloudflare Access. Users authenticate with their identity provider, Cloudflare verifies identity and device posture, and only then is a session established. The application has no public IP. It is not reachable from the internet directly.</p><p>A stolen credential does not give an attacker network access. It gives them an authentication challenge they cannot pass without the right device and second factor. That is a fundamentally different security posture from “here is the VPN, try not to share your credentials.”</p><p>What we retired: a self-managed OpenVPN setup on EC2, two years of key rotation headaches, and the slow creep of users who had VPN access long after they needed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*cv1fIzDOkmIpFrI6" /></figure><p><strong>Cloud SSH via Cloudflare Tunnel — no bastion host</strong></p><p>“No bastion host. Full stop.”</p><p>Cloudflare Tunnel creates an outbound-only encrypted connection from our infrastructure to Cloudflare’s edge. Our instances initiate the connection outward — nothing listens inbound. SSH sessions from engineers flow through Cloudflare Access, through the tunnel, directly to the target. Our NACLs block port 22 from 0.0.0.0/0. There is nothing to scan. The attack surface for SSH is literally zero.</p><p>We ran a bastion host for years. It was patched irregularly. It had stale security group rules. It was one of those things that everyone knew was a problem and nobody had time to fix. Retiring it felt like putting down a weight we had been carrying for too long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*4GPhdFGWkSMCxHYi" /></figure><p><strong>DDoS protection — unmetered</strong></p><p>Cloudflare absorbs volumetric attacks at their edge. Their mitigation capacity is measured in terabits per second. The free tier includes unmetered DDoS mitigation. AWS Shield Advanced — the equivalent AWS service — costs $3,000 per month, billed annually upfront.</p><p><strong>WAF — OWASP Top 10 for free</strong></p><p>Cloudflare’s WAF sits in front of internet-facing applications and covers SQL injection, cross-site scripting, path traversal, and the rest of the standard attack catalogue. Rules are maintained by Cloudflare. We do not manage signatures.</p><p><strong>DNS Proxy — the hidden origin</strong></p><p>This is the one people skip over and they should not.</p><p>We use Cloudflare proxy mode, not just DNS hosting. All traffic to our domains resolves to Cloudflare’s anycast IPs. Our real server IPs are never exposed. An attacker cannot bypass Cloudflare by targeting the origin directly because they do not know what it is. DNSSEC prevents spoofing. DNS-level DDoS hits Cloudflare’s infrastructure, not ours.</p><h3>AWS Route 53 DNS Firewall — outbound domain control</h3><p>While Cloudflare handles inbound threats at the edge, DNS Firewall handles the opposite direction. Every DNS query leaving any spoke VPC routes through the central hub. DNS Firewall intercepts every lookup before a connection forms.</p><p>Before any EC2 instance can reach a malicious domain, it has to ask DNS for the address. DNS Firewall answers first. If the domain is on a block list, the answer is nothing. The connection never forms. The kill chain breaks before a single byte leaves the network.</p><p><strong>IOC blocking that actually works</strong></p><p>When our security team receives a new Indicator of Compromise — a malicious domain from a threat feed, something flagged during an incident, a vendor advisory — the process used to involve a change request, a proxy config update, and a deployment window. Days, not minutes.</p><p>Now the workflow is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8HsEmsAhlOKwHzCNLoszA.png" /></figure><p>Threat feed flags a new C2 domain. Security team adds it to our DNS Firewall custom domain list. Takes about sixty seconds. Route 53 Resolver propagates the block to every associated VPC across every account automatically. Within five minutes of receiving the IOC, every compute resource in our entire organisation is blocking that domain. If any instance had already tried to resolve it, that query shows up in Security Hub and we know exactly which instance to investigate.</p><p><strong>AWS Managed Threat Lists</strong></p><p>AWS maintains curated lists of known malware command-and-control domains, botnet infrastructure, and phishing sites. They update them continuously. We subscribe and they apply automatically.</p><p>No threat feed subscription. No manual list management. No signature updates to schedule. Free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/0*V-0-kmXEsLzYjTD9" /></figure><h3>Network ACLs — layers 3 and 4, zero cost</h3><p>NACLs are the most underrated security control in AWS and most teams barely use them.</p><p>They are stateless, subnet-level, support explicit DENY rules — which Security Groups cannot do — and they cost nothing. In a hub-and-spoke model they enforce at every subnet boundary across every spoke VPC. No individual resource can bypass or misconfigure around them. A misconfigured Security Group, a developer who opened a port they should not have, an instance with overly permissive rules — the NACL catches it anyway.</p><p>Our inbound rules permanently deny port 22 and 3389 from the internet, database ports from internet-facing access, Tor exit node CIDRs, and geographic IP ranges we have no business receiving traffic from.</p><p>Our outbound rules deny common reverse shell ports, IRC ports still used by older botnet infrastructure, and anything that does not route through our central hub egress. All spoke VPC traffic must go through the hub. No exceptions, no bypass.</p><p>The combination with DNS Firewall matters. DNS Firewall kills domain-based threats at Layer 7 before connections form. NACLs kill port and IP-based threats at Layers 3 and 4 regardless of what domain was queried. Two independent layers. No shared failure mode.</p><p>Cost: zero.</p><h3>GuardDuty — IDS, runtime monitoring, and antivirus</h3><p>This is the layer that most surprised us when we looked carefully at what it actually covers.</p><p>GuardDuty replaced three separate things we were either paying for or trying to build ourselves: a network IDS, endpoint antivirus, and runtime behavioural monitoring.</p><p><strong>As an IDS</strong></p><p>GuardDuty continuously analyses VPC Flow Logs, CloudTrail events, and DNS query logs across every account in our organisation. Machine learning plus AWS threat intelligence detects port scanning and reconnaissance, unusual API call patterns that suggest credential compromise, communication with known threat actor infrastructure, lateral movement between instances, and data exfiltration patterns.</p><p>It works from logs. Zero performance impact on workloads. Nothing inline. Nothing to size or maintain.</p><p><strong>Trusted and Untrusted IP Lists</strong></p><p>We configure two types of custom IP lists in GuardDuty and both matter.</p><p>Trusted IP lists contain our known-safe ranges — corporate IPs, CI/CD infrastructure, monitoring systems. GuardDuty suppresses findings for activity from these IPs. This eliminates the noise of legitimate internal tooling triggering false positives and means every alert that reaches our analyst is actually worth looking at.</p><p>Threat IP lists contain known-malicious IPs from our threat feeds — C2 infrastructure, IPs flagged in previous incidents, addresses our team has manually identified. Any communication between our resources and these IPs triggers a finding immediately. This is IP-layer IOC detection, complementing DNS Firewall’s domain-layer IOC blocking. Same concept, different protocol layer, fully independent.</p><p><strong>Runtime Monitoring</strong></p><p>GuardDuty Runtime Monitoring places a lightweight sensor on EC2 instances and containers that monitors system calls. It catches processes accessing files they should not touch, unexpected network connections from inside containers, privilege escalation attempts, reverse shell activity, and cryptocurrency mining — all at the system call level, below where most application-layer defences operate.</p><p>If malware lands inside an instance and tries to do anything, Runtime Monitoring sees it regardless of what domain or IP it tries to reach.</p><p><strong>Malware Protection — replacing endpoint antivirus</strong></p><p>GuardDuty Malware Protection scans EBS volumes when suspicious activity is detected. AWS-maintained threat signatures. No antivirus agent. No signature update schedule. No performance overhead during normal operation. The scan triggers on suspicion, not continuously.</p><p>We had endpoint antivirus running on our EC2 fleet for years. It consumed CPU. It caused compatibility issues on AMI updates. It needed its own update management. Replacing it with GuardDuty Malware Protection was one of the cleaner operational improvements we made — less overhead, better coverage, no agent sprawl.</p><h3>Security Hub — one place for everything</h3><p>Since January 2025, Security Hub natively integrates with Route 53 Resolver DNS Firewall. Every finding flows in — DNS Firewall blocked query alerts, GuardDuty detections, runtime alerts, malware findings, Inspector vulnerability findings, Macie data alerts.</p><p>When GuardDuty flags an instance for unusual outbound behaviour and DNS Firewall shows that same instance attempted to resolve a blocked IOC domain, both findings are correlated in Security Hub. The analyst does not need to pivot between tools. The context is already assembled.</p><p>One dashboard. One analyst. Full picture across every account.</p><h3>What This Covers and What It Does Not</h3><p>Full honesty here.</p><p>We do not have deep packet inspection on encrypted traffic to unknown domains. If an attacker sends malicious payload over HTTPS to a brand-new domain not yet on any threat list, DNS Firewall will not catch the payload. AWS Network Firewall with TLS inspection would.</p><p>We do not have inline IPS. We do not match packet signatures against known exploits in transit.</p><p>For our threat model — cloud-native workloads, external-origin threats, malware callbacks, IOC-based attack infrastructure — this stack covers what actually happens to organisations like ours. The gaps are real but narrow for our specific situation.</p><p>If you are operating under PCI-DSS Level 1 with specific deep inspection audit requirements, or you are running financial transaction systems with strict regulatory controls around traffic inspection, evaluate whether you need Network Firewall on top of this. That is a legitimate use case for it.</p><p>For most cloud-native teams building on AWS: this stack is the right answer and the trade-off is consciously made.</p><h3>The Actual Cost</h3><h4>Cost-Optimized Security Stack</h4><ul><li>Cloudflare Zero Trust, WAF, DDoS, DNS Proxy, Tunnel — <strong>$0</strong></li><li>NACLs — <strong>$0</strong></li><li>AWS Managed Threat Lists — <strong>$0</strong></li><li>Route 53 DNS Firewall (~30M queries) — <strong>$18</strong></li><li>GuardDuty — <strong>$50</strong></li><li>Security Hub — <strong>$5</strong></li><li>Custom domain lists — <strong>$0.25</strong></li></ul><p><strong>Total: $73/month</strong></p><h3><strong>What we avoided:</strong></h3><h4>Traditional Security Stack (Avoided)</h4><ul><li>AWS Network Firewall — <strong>$900</strong></li><li>AWS Shield Advanced — <strong>$3,000</strong></li><li>NGFW license — <strong>$2,000</strong></li><li>Commercial WAF — <strong>$300</strong></li><li>IDS appliance — <strong>$500</strong></li><li>Antivirus fleet — <strong>$200</strong></li><li>VPN EC2 — <strong>$50</strong></li><li>Bastion host — <strong>$30</strong></li></ul><p><strong>Total avoided: $6,980/month</strong></p><p>Annual saving: roughly $83,000 compared to the full traditional stack.</p><p>That saving funded three other security investments we actually needed.</p><h3>The Bit That Took Us Longest to Internalize</h3><p>Security is not about having the most comprehensive product on paper.</p><p>It is about defending the right layers with the right controls and knowing exactly what trade-off you are making. Every expensive security product exists because it solves a real problem. The question is whether you are the right target for that solution, at that price, at this stage.</p><p>Cloudflare at the edge. DNS Firewall for outbound domain control. NACLs for stateless subnet enforcement. GuardDuty for behavioural IDS, runtime detection, and malware scanning. Security Hub to correlate everything.</p><p>L3 through L7. Inbound and outbound. User access and workload egress. IOC blocking with a five-minute response time. $73 a month.</p><p>We are not claiming this is perfect. We are claiming it is genuinely good, deliberately chosen, and appropriate for how we actually operate.</p><p>If your threat model is different, your stack should be different. But if you are a cloud-native team on AWS spending serious money on a Network Firewall or NGFW appliance without having seriously evaluated this combination first — it might be worth the conversation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*wUk84LFHaiR-REmq" /></figure><p><em>Building something similar or thinking through the trade-offs between Network Firewall and this kind of layered approach? Happy to talk through the specific design decisions. Drop a comment or connect.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=014d5027efba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloudflare Zero Trust + AWS: Architecture Deep Dive & Implementation Guide]]></title>
            <link>https://medium.com/@awsyadav/cloudflare-zero-trust-aws-architecture-deep-dive-implementation-guide-1f8d08f20207?source=rss-5e4b71f714d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f8d08f20207</guid>
            <category><![CDATA[cloud-networking]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[zero-trust]]></category>
            <category><![CDATA[vpn]]></category>
            <dc:creator><![CDATA[Sandeep Yadav]]></dc:creator>
            <pubDate>Fri, 10 Apr 2026 06:48:03 GMT</pubDate>
            <atom:updated>2026-04-10T06:48:03.334Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmaVcw3p4ZmhCn1Kd_JmCg.jpeg" /></figure><h3>Cloudflare Zero Trust + AWS: Architecture Deep Dive &amp; Implementation Guide</h3><p>Traditional perimeter-based security — the “castle and moat” model — assumes everything inside the network is trusted. That assumption is dangerously outdated. With remote workforces, multi-cloud environments, and SaaS sprawl, the perimeter no longer exists.</p><p>Cloudflare Zero Trust replaces the VPN with a model where every login, every request, and every device is verified — regardless of where the user sits or what network they are on. Combined with AWS Transit Gateway for multi-account routing, this architecture delivers secure, scalable, and auditable access to private cloud resources without exposing them to the internet.</p><p>This blog walks through:</p><ul><li>What Cloudflare Zero Trust is and how it works</li><li>The AWS multi-account architecture it integrates with</li><li>Step-by-step Terraform implementation</li></ul><h3>What Is Cloudflare Zero Trust?</h3><p>Cloudflare Zero Trust is a SASE (Secure Access Service Edge) platform that sits between your users and your resources. It verifies identity, device health, and context before allowing any connection — and it does this at Cloudflare’s global edge network.</p><h3>Core Components</h3><p><strong>Secure Access (ZTNA)</strong> Replaces VPN. Users connect to private apps via Cloudflare’s network, never touching the public internet or directly reaching your infrastructure. Access policies are enforced at the edge.</p><p><strong>Internet Gateway (SWG)</strong> All user internet traffic is proxied through Cloudflare’s Secure Web Gateway. DNS filtering, HTTP inspection, and threat blocking happen inline.</p><p><strong>SaaS App Security (CASB)</strong> Visibility and access control over sanctioned SaaS applications including Microsoft 365, Google Workspace, and Salesforce.</p><p><strong>Browser Isolation</strong> Remote browsing sessions run in Cloudflare’s cloud — malicious code never executes on the endpoint.</p><p><strong>Cloud Email Security</strong> Anti-phishing, BEC detection, and malware scanning for inbound and outbound email.</p><p><strong>Data Loss Prevention (DLP)</strong> Inspect traffic for sensitive data patterns such as credit card numbers, PII, and credentials before they leave your environment.</p><h3>Key Benefits</h3><ul><li>VPN replacement: any user, any device, any resource — without a VPN client tunnel to a data centre</li><li>Internet protection: all ports and protocols covered, not just port 80/443</li><li>SaaS security: unified visibility including email</li><li>Security modernisation: reduced attack surface, improved productivity, simpler operations</li></ul><h3>Architecture Overview</h3><p>The architecture consists of three logical planes:</p><h3>1. User Plane — Cloudflare WARP Client</h3><p>Users install the Cloudflare WARP client on their laptops or mobile devices. WARP encrypts all traffic and routes it to the nearest Cloudflare regional data centre. This is the on-ramp to Zero Trust enforcement.</p><h3>2. Enforcement Plane — Cloudflare Zero Trust Dashboard</h3><p>Every connection request is evaluated against policies built on three inputs:</p><p><strong>WHAT (identity):</strong></p><ul><li>Multiple identity providers (Okta, Azure AD, Google, etc.)</li><li>Device security posture (certificate, OS version, disk encryption, endpoint agent)</li><li>Contextual factors (country, time of day, risk score)</li></ul><p><strong>HOW (access method):</strong></p><ul><li>Firewall-protected private routing via Cloudflare Tunnel</li><li>DDoS-protected reverse proxy for public-facing apps</li><li>In-browser terminal for SSH/RDP without port exposure</li></ul><p>If all conditions pass, the connection is proxied through a Cloudflare Tunnel to your infrastructure. If any condition fails, the connection is blocked or step-up authentication is triggered.</p><h3>3. Infrastructure Plane — AWS Multi-Account</h3><p>On the AWS side, the architecture uses a hub-and-spoke model:</p><pre>Cloudflare Tunnel<br>       │<br>       ▼<br> Network Account (Hub VPC)<br>       │<br>  ┌────┴────┐<br>  │   TGW   │  ← Transit Gateway<br>  └────┬────┘<br>       │<br>  ┌────┼────┐<br>  ▼    ▼    ▼<br>Prod  Dev  Stage  ← Spoke Accounts</pre><p><strong>Network Account:</strong> Hosts the Cloudflare Connectors deployed in private subnets across two Availability Zones (AZ1 and AZ2) for high availability. The connectors establish outbound-only tunnels to Cloudflare — no inbound firewall rules needed. A Transit Gateway Attachment connects this VPC to the TGW.</p><p><strong>Transit Gateway (TGW):</strong> Acts as the central router. TGW Routing Tables map CIDR ranges (172.16.0.0/24, 172.16.1.0/24, 172.16.2.0/24) to the correct spoke accounts. Route propagation is controlled via TGW Route Tables, not VPC peering — keeping the design flat and auditable.</p><p><strong>Spoke Accounts (Prod / Dev / Stage):</strong> Each account has its own VPC with private subnets. A TGW Attachment connects each spoke VPC to the Transit Gateway. Local TGW Route Tables in each spoke control which prefixes are advertised back to the hub.</p><p><strong>Traffic flow:</strong></p><pre>User → WARP → Cloudflare Regional DC<br>     → Cloudflare Tunnel<br>     → CF Connector (AZ1 or AZ2, Network Account)<br>     → TGW Attachment<br>     → TGW Routing Tables<br>     → Spoke VPC (Prod / Dev / Stage)<br>     → Private Subnet → Application</pre><p>No traffic touches the public internet after the Cloudflare edge. No security groups need to allow inbound from user IPs. The connector pulls the tunnel — the cloud resource never opens a port.</p><h3>Terraform Implementation</h3><p>The implementation is split into four modules:</p><ol><li>cloudflare-zt — Zero Trust account, tunnel, and access policies</li><li>network-account — Hub VPC, subnets, CF Connectors, TGW</li><li>spoke-account — Per-environment VPC and TGW attachment (repeated for Prod/Dev/Stage)</li><li>tgw-routing — Centralised route table management</li></ol><h3>Module 1: Cloudflare Zero Trust &amp; Tunnel</h3><pre># modules/cloudflare-zt/main.tf</pre><pre>terraform {<br>  required_providers {<br>    cloudflare = {<br>      source  = &quot;cloudflare/cloudflare&quot;<br>      version = &quot;~&gt; 4.0&quot;<br>    }<br>  }<br>}</pre><pre>variable &quot;account_id&quot;       { type = string }<br>variable &quot;tunnel_secret&quot;    { type = string; sensitive = true }<br>variable &quot;organization_name&quot;{ type = string }<br>variable &quot;idp_client_id&quot;    { type = string }<br>variable &quot;idp_client_secret&quot;{ type = string; sensitive = true }</pre><pre># --- Zero Trust Organization ---<br>resource &quot;cloudflare_teams_account&quot; &quot;main&quot; {<br>  account_id                         = var.account_id<br>  tls_decrypt_enabled                = true<br>  protocol_detection_enabled         = true<br>  block_page_enabled                 = true<br>  block_page_footer_text             = &quot;Contact IT for access.&quot;<br>  non_identity_browser_isolation_enabled = false<br>}</pre><pre># --- Identity Provider (Azure AD example) ---<br>resource &quot;cloudflare_access_identity_provider&quot; &quot;azure_ad&quot; {<br>  account_id = var.account_id<br>  name       = &quot;Azure Active Directory&quot;<br>  type       = &quot;azureAD&quot;</pre><pre>  config {<br>    client_id     = var.idp_client_id<br>    client_secret = var.idp_client_secret<br>    directory_id  = var.azure_tenant_id<br>  }<br>}</pre><pre># --- Cloudflare Tunnel (named tunnel) ---<br>resource &quot;cloudflare_tunnel&quot; &quot;aws_private&quot; {<br>  account_id = var.account_id<br>  name       = &quot;aws-private-network&quot;<br>  secret     = base64encode(var.tunnel_secret)<br>}</pre><pre># --- Tunnel Config: route private CIDRs ---<br>resource &quot;cloudflare_tunnel_config&quot; &quot;aws_private&quot; {<br>  account_id = var.account_id<br>  tunnel_id  = cloudflare_tunnel.aws_private.id</pre><pre>  config {<br>    ingress_rule {<br>      hostname = &quot;&quot;<br>      service  = &quot;http://localhost:8080&quot;<br>    }</pre><pre>    warp_routing {<br>      enabled = true<br>    }<br>  }<br>}</pre><pre># --- Private Network Routes via Tunnel ---<br>resource &quot;cloudflare_tunnel_route&quot; &quot;prod&quot; {<br>  account_id = var.account_id<br>  tunnel_id  = cloudflare_tunnel.aws_private.id<br>  network    = &quot;172.16.0.0/24&quot;<br>  comment    = &quot;Prod account private subnet&quot;<br>}</pre><pre>resource &quot;cloudflare_tunnel_route&quot; &quot;dev&quot; {<br>  account_id = var.account_id<br>  tunnel_id  = cloudflare_tunnel.aws_private.id<br>  network    = &quot;172.16.1.0/24&quot;<br>  comment    = &quot;Dev account private subnet&quot;<br>}</pre><pre>resource &quot;cloudflare_tunnel_route&quot; &quot;stage&quot; {<br>  account_id = var.account_id<br>  tunnel_id  = cloudflare_tunnel.aws_private.id<br>  network    = &quot;172.16.2.0/24&quot;<br>  comment    = &quot;Stage account private subnet&quot;<br>}</pre><pre># --- Device Posture: require disk encryption ---<br>resource &quot;cloudflare_device_posture_rule&quot; &quot;disk_encryption&quot; {<br>  account_id  = var.account_id<br>  name        = &quot;Disk Encryption Required&quot;<br>  type        = &quot;disk_encryption&quot;<br>  description = &quot;Endpoint must have full disk encryption enabled&quot;</pre><pre>  match {<br>    platform = &quot;windows&quot;<br>  }</pre><pre>  match {<br>    platform = &quot;mac&quot;<br>  }<br>}</pre><pre># --- Zero Trust Access Policy ---<br>resource &quot;cloudflare_access_policy&quot; &quot;private_network&quot; {<br>  account_id = var.account_id<br>  name       = &quot;Private Network Access&quot;<br>  decision   = &quot;allow&quot;<br>  precedence = 1</pre><pre>  include {<br>    group = [cloudflare_access_group.corp_users.id]<br>  }</pre><pre>  require {<br>    device_posture = [cloudflare_device_posture_rule.disk_encryption.id]<br>  }<br>}</pre><pre>resource &quot;cloudflare_access_group&quot; &quot;corp_users&quot; {<br>  account_id = var.account_id<br>  name       = &quot;Corporate Users&quot;</pre><pre>  include {<br>    login_method = [cloudflare_access_identity_provider.azure_ad.id]<br>  }<br>}</pre><pre># --- Gateway DNS Policy: block malware categories ---<br>resource &quot;cloudflare_teams_rule&quot; &quot;block_malware&quot; {<br>  account_id  = var.account_id<br>  name        = &quot;Block Malware &amp; Phishing&quot;<br>  description = &quot;Block known threat categories at DNS level&quot;<br>  precedence  = 1<br>  action      = &quot;block&quot;<br>  filters     = [&quot;dns&quot;]</pre><pre>  traffic = &quot;any(dns.security_category[*] in {68 117 131 153})&quot;<br>}</pre><pre>output &quot;tunnel_id&quot;    { value = cloudflare_tunnel.aws_private.id }<br>output &quot;tunnel_token&quot; { value = cloudflare_tunnel.aws_private.tunnel_token; sensitive = true }</pre><h3>Module 2: Network Account — Hub VPC &amp; Cloudflare Connectors</h3><pre># modules/network-account/main.tf</pre><pre>variable &quot;region&quot;          { default = &quot;us-east-1&quot; }<br>variable &quot;vpc_cidr&quot;        { default = &quot;10.0.0.0/16&quot; }<br>variable &quot;tunnel_token&quot;    { type = string; sensitive = true }<br>variable &quot;connector_image&quot; { default = &quot;cloudflare/cloudflared:latest&quot; }</pre><pre>provider &quot;aws&quot; {<br>  region = var.region<br>}</pre><pre># --- VPC ---<br>resource &quot;aws_vpc&quot; &quot;network_hub&quot; {<br>  cidr_block           = var.vpc_cidr<br>  enable_dns_support   = true<br>  enable_dns_hostnames = true</pre><pre>  tags = { Name = &quot;network-hub-vpc&quot; }<br>}</pre><pre># --- Private Subnets (AZ1 and AZ2) ---<br>resource &quot;aws_subnet&quot; &quot;private_az1&quot; {<br>  vpc_id            = aws_vpc.network_hub.id<br>  cidr_block        = &quot;10.0.1.0/24&quot;<br>  availability_zone = &quot;${var.region}a&quot;</pre><pre>  tags = { Name = &quot;network-hub-private-az1&quot; }<br>}</pre><pre>resource &quot;aws_subnet&quot; &quot;private_az2&quot; {<br>  vpc_id            = aws_vpc.network_hub.id<br>  cidr_block        = &quot;10.0.2.0/24&quot;<br>  availability_zone = &quot;${var.region}b&quot;</pre><pre>  tags = { Name = &quot;network-hub-private-az2&quot; }<br>}</pre><pre># --- Transit Gateway ---<br>resource &quot;aws_ec2_transit_gateway&quot; &quot;main&quot; {<br>  description                     = &quot;Central TGW for multi-account routing&quot;<br>  default_route_table_association = &quot;disable&quot;<br>  default_route_table_propagation = &quot;disable&quot;<br>  auto_accept_shared_attachments  = &quot;enable&quot;</pre><pre>  tags = { Name = &quot;central-tgw&quot; }<br>}</pre><pre># --- TGW Attachment for Network Account ---<br>resource &quot;aws_ec2_transit_gateway_vpc_attachment&quot; &quot;network_hub&quot; {<br>  transit_gateway_id = aws_ec2_transit_gateway.main.id<br>  vpc_id             = aws_vpc.network_hub.id<br>  subnet_ids         = [aws_subnet.private_az1.id, aws_subnet.private_az2.id]</pre><pre>  tags = { Name = &quot;network-hub-tgw-attach&quot; }<br>}</pre><pre># --- TGW Route Table ---<br>resource &quot;aws_ec2_transit_gateway_route_table&quot; &quot;main&quot; {<br>  transit_gateway_id = aws_ec2_transit_gateway.main.id<br>  tags               = { Name = &quot;central-tgw-rt&quot; }<br>}</pre><pre>resource &quot;aws_ec2_transit_gateway_route_table_association&quot; &quot;network_hub&quot; {<br>  transit_gateway_attachment_id  = aws_ec2_transit_gateway_vpc_attachment.network_hub.id<br>  transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.main.id<br>}</pre><pre># --- Security Group for CF Connectors ---<br>resource &quot;aws_security_group&quot; &quot;cf_connector&quot; {<br>  name        = &quot;cf-connector-sg&quot;<br>  description = &quot;Cloudflare Connector — outbound only&quot;<br>  vpc_id      = aws_vpc.network_hub.id</pre><pre>  egress {<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>    description = &quot;Cloudflare Tunnel HTTPS&quot;<br>  }</pre><pre>  egress {<br>    from_port   = 7844<br>    to_port     = 7844<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>    description = &quot;Cloudflare Tunnel QUIC&quot;<br>  }</pre><pre>  tags = { Name = &quot;cf-connector-sg&quot; }<br>}</pre><pre># --- ECS Cluster for Connectors ---<br>resource &quot;aws_ecs_cluster&quot; &quot;cf_connectors&quot; {<br>  name = &quot;cloudflare-connectors&quot;<br>}</pre><pre># --- IAM Role for ECS Tasks ---<br>resource &quot;aws_iam_role&quot; &quot;ecs_task_execution&quot; {<br>  name = &quot;cf-connector-ecs-execution-role&quot;</pre><pre>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Action    = &quot;sts:AssumeRole&quot;<br>      Effect    = &quot;Allow&quot;<br>      Principal = { Service = &quot;ecs-tasks.amazonaws.com&quot; }<br>    }]<br>  })<br>}</pre><pre>resource &quot;aws_iam_role_policy_attachment&quot; &quot;ecs_task_execution&quot; {<br>  role       = aws_iam_role.ecs_task_execution.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy&quot;<br>}</pre><pre># --- SSM Parameter for Tunnel Token (secure storage) ---<br>resource &quot;aws_ssm_parameter&quot; &quot;tunnel_token&quot; {<br>  name        = &quot;/cloudflare/tunnel/token&quot;<br>  type        = &quot;SecureString&quot;<br>  value       = var.tunnel_token<br>  description = &quot;Cloudflare Named Tunnel token&quot;<br>}</pre><pre># --- ECS Task Definition: Cloudflare Connector ---<br>resource &quot;aws_ecs_task_definition&quot; &quot;cf_connector&quot; {<br>  family                   = &quot;cloudflare-connector&quot;<br>  network_mode             = &quot;awsvpc&quot;<br>  requires_compatibilities = [&quot;FARGATE&quot;]<br>  cpu                      = &quot;256&quot;<br>  memory                   = &quot;512&quot;<br>  execution_role_arn       = aws_iam_role.ecs_task_execution.arn</pre><pre>  container_definitions = jsonencode([{<br>    name      = &quot;cloudflared&quot;<br>    image     = var.connector_image<br>    essential = true</pre><pre>    command = [&quot;tunnel&quot;, &quot;--no-autoupdate&quot;, &quot;run&quot;]</pre><pre>    secrets = [{<br>      name      = &quot;TUNNEL_TOKEN&quot;<br>      valueFrom = aws_ssm_parameter.tunnel_token.arn<br>    }]</pre><pre>    logConfiguration = {<br>      logDriver = &quot;awslogs&quot;<br>      options = {<br>        awslogs-group         = &quot;/ecs/cloudflare-connector&quot;<br>        awslogs-region        = var.region<br>        awslogs-stream-prefix = &quot;connector&quot;<br>      }<br>    }<br>  }])<br>}</pre><pre># --- CloudWatch Log Group ---<br>resource &quot;aws_cloudwatch_log_group&quot; &quot;cf_connector&quot; {<br>  name              = &quot;/ecs/cloudflare-connector&quot;<br>  retention_in_days = 30<br>}</pre><pre># --- ECS Service: AZ1 ---<br>resource &quot;aws_ecs_service&quot; &quot;cf_connector_az1&quot; {<br>  name            = &quot;cf-connector-az1&quot;<br>  cluster         = aws_ecs_cluster.cf_connectors.id<br>  task_definition = aws_ecs_task_definition.cf_connector.arn<br>  desired_count   = 1<br>  launch_type     = &quot;FARGATE&quot;</pre><pre>  network_configuration {<br>    subnets          = [aws_subnet.private_az1.id]<br>    security_groups  = [aws_security_group.cf_connector.id]<br>    assign_public_ip = false<br>  }<br>}</pre><pre># --- ECS Service: AZ2 ---<br>resource &quot;aws_ecs_service&quot; &quot;cf_connector_az2&quot; {<br>  name            = &quot;cf-connector-az2&quot;<br>  cluster         = aws_ecs_cluster.cf_connectors.id<br>  task_definition = aws_ecs_task_definition.cf_connector.arn<br>  desired_count   = 1<br>  launch_type     = &quot;FARGATE&quot;</pre><pre>  network_configuration {<br>    subnets          = [aws_subnet.private_az2.id]<br>    security_groups  = [aws_security_group.cf_connector.id]<br>    assign_public_ip = false<br>  }<br>}</pre><pre>output &quot;tgw_id&quot;           { value = aws_ec2_transit_gateway.main.id }<br>output &quot;tgw_route_table&quot;  { value = aws_ec2_transit_gateway_route_table.main.id }<br>output &quot;tgw_attachment_id&quot;{ value = aws_ec2_transit_gateway_vpc_attachment.network_hub.id }</pre><h3>Module 3: Spoke Account (Prod / Dev / Stage)</h3><pre># modules/spoke-account/main.tf<br># Instantiate once per environment with different variables</pre><pre>variable &quot;environment&quot;       { type = string }  # prod | dev | stage<br>variable &quot;vpc_cidr&quot;          { type = string }  # e.g. 172.16.0.0/24<br>variable &quot;private_subnets&quot;   { type = list(string) }<br>variable &quot;tgw_id&quot;            { type = string }<br>variable &quot;tgw_route_table_id&quot;{ type = string }<br>variable &quot;region&quot;            { default = &quot;us-east-1&quot; }</pre><pre>provider &quot;aws&quot; {<br>  region = var.region<br>}</pre><pre># --- VPC ---<br>resource &quot;aws_vpc&quot; &quot;spoke&quot; {<br>  cidr_block           = var.vpc_cidr<br>  enable_dns_support   = true<br>  enable_dns_hostnames = true</pre><pre>  tags = { Name = &quot;${var.environment}-vpc&quot; }<br>}</pre><pre># --- Private Subnets ---<br>resource &quot;aws_subnet&quot; &quot;private&quot; {<br>  count             = length(var.private_subnets)<br>  vpc_id            = aws_vpc.spoke.id<br>  cidr_block        = var.private_subnets[count.index]<br>  availability_zone = &quot;${var.region}${[&quot;a&quot;,&quot;b&quot;][count.index]}&quot;</pre><pre>  tags = { Name = &quot;${var.environment}-private-${count.index + 1}&quot; }<br>}</pre><pre># --- TGW Attachment ---<br>resource &quot;aws_ec2_transit_gateway_vpc_attachment&quot; &quot;spoke&quot; {<br>  transit_gateway_id = var.tgw_id<br>  vpc_id             = aws_vpc.spoke.id<br>  subnet_ids         = aws_subnet.private[*].id</pre><pre>  tags = { Name = &quot;${var.environment}-tgw-attach&quot; }<br>}</pre><pre># --- Associate with central TGW Route Table ---<br>resource &quot;aws_ec2_transit_gateway_route_table_association&quot; &quot;spoke&quot; {<br>  transit_gateway_attachment_id  = aws_ec2_transit_gateway_vpc_attachment.spoke.id<br>  transit_gateway_route_table_id = var.tgw_route_table_id<br>}</pre><pre># --- Propagate spoke routes into TGW Route Table ---<br>resource &quot;aws_ec2_transit_gateway_route_table_propagation&quot; &quot;spoke&quot; {<br>  transit_gateway_attachment_id  = aws_ec2_transit_gateway_vpc_attachment.spoke.id<br>  transit_gateway_route_table_id = var.tgw_route_table_id<br>}</pre><pre># --- VPC Route: send all RFC1918 traffic to TGW ---<br>resource &quot;aws_route_table&quot; &quot;private&quot; {<br>  vpc_id = aws_vpc.spoke.id<br>  tags   = { Name = &quot;${var.environment}-private-rt&quot; }<br>}</pre><pre>resource &quot;aws_route&quot; &quot;to_tgw&quot; {<br>  route_table_id         = aws_route_table.private.id<br>  destination_cidr_block = &quot;10.0.0.0/8&quot;<br>  transit_gateway_id     = var.tgw_id<br>}</pre><pre>resource &quot;aws_route_table_association&quot; &quot;private&quot; {<br>  count          = length(aws_subnet.private)<br>  subnet_id      = aws_subnet.private[count.index].id<br>  route_table_id = aws_route_table.private.id<br>}</pre><pre>output &quot;vpc_id&quot;         { value = aws_vpc.spoke.id }<br>output &quot;attachment_id&quot;  { value = aws_ec2_transit_gateway_vpc_attachment.spoke.id }</pre><h3>Root Module: Wiring It All Together</h3><pre># main.tf (root)</pre><pre>module &quot;cloudflare_zt&quot; {<br>  source             = &quot;./modules/cloudflare-zt&quot;<br>  account_id         = var.cloudflare_account_id<br>  tunnel_secret      = var.cloudflare_tunnel_secret<br>  organization_name  = &quot;My Organisation&quot;<br>  idp_client_id      = var.azure_client_id<br>  idp_client_secret  = var.azure_client_secret<br>}</pre><pre>module &quot;network_account&quot; {<br>  source       = &quot;./modules/network-account&quot;<br>  region       = &quot;us-east-1&quot;<br>  tunnel_token = module.cloudflare_zt.tunnel_token<br>}</pre><pre>module &quot;prod&quot; {<br>  source              = &quot;./modules/spoke-account&quot;<br>  environment         = &quot;prod&quot;<br>  vpc_cidr            = &quot;172.16.0.0/24&quot;<br>  private_subnets     = [&quot;172.16.0.0/25&quot;, &quot;172.16.0.128/25&quot;]<br>  tgw_id              = module.network_account.tgw_id<br>  tgw_route_table_id  = module.network_account.tgw_route_table<br>}</pre><pre>module &quot;dev&quot; {<br>  source              = &quot;./modules/spoke-account&quot;<br>  environment         = &quot;dev&quot;<br>  vpc_cidr            = &quot;172.16.1.0/24&quot;<br>  private_subnets     = [&quot;172.16.1.0/25&quot;, &quot;172.16.1.128/25&quot;]<br>  tgw_id              = module.network_account.tgw_id<br>  tgw_route_table_id  = module.network_account.tgw_route_table<br>}</pre><pre>module &quot;stage&quot; {<br>  source              = &quot;./modules/spoke-account&quot;<br>  environment         = &quot;stage&quot;<br>  vpc_cidr            = &quot;172.16.2.0/24&quot;<br>  private_subnets     = [&quot;172.16.2.0/25&quot;, &quot;172.16.2.128/25&quot;]<br>  tgw_id              = module.network_account.tgw_id<br>  tgw_route_table_id  = module.network_account.tgw_route_table<br>}</pre><h3>Variables File</h3><pre># variables.tf</pre><pre>variable &quot;cloudflare_account_id&quot;  { type = string }<br>variable &quot;cloudflare_tunnel_secret&quot;{ type = string; sensitive = true }<br>variable &quot;azure_client_id&quot;        { type = string }<br>variable &quot;azure_client_secret&quot;    { type = string; sensitive = true }<br>variable &quot;azure_tenant_id&quot;        { type = string }</pre><h3>Deployment Steps</h3><ol><li>Configure Terraform backend (S3 + DynamoDB recommended for state locking)</li><li>Export credentials:</li></ol><pre>export CLOUDFLARE_API_TOKEN=&lt;your-token&gt;<br>export AWS_PROFILE=network-account</pre><p>3. Initialise and apply:</p><pre>terraform init<br>terraform plan -out=tfplan<br>terraform apply tfplan</pre><p>4. Verify connectors in Cloudflare dashboard under Networks &gt; Tunnels — both AZ1 and AZ2 instances should show as HEALTHY.</p><p>5. Enable WARP-to-Tunnel routing in the Zero Trust dashboard under Settings &gt; WARP Client &gt; Device enrollment.</p><p>6. Test from a WARP-enrolled device:</p><pre>curl http://172.16.0.10    # prod private IP<br>curl http://172.16.1.10    # dev private IP</pre><h3>Security Hardening Checklist</h3><ul><li>Use AWS Resource Access Manager (RAM) to share the Transit Gateway across accounts without making it public</li><li>Store the tunnel token exclusively in AWS SSM Parameter Store with KMS encryption — never in plaintext or environment variables</li><li>Enable Cloudflare Access audit logs and stream them to your SIEM via Logpush</li><li>Create separate Cloudflare Access policies per environment (prod requires MFA; dev allows broader group)</li><li>Use default_route_table_association = &quot;disable&quot; on the TGW — always assign attachments to explicit route tables</li><li>Enable VPC Flow Logs on the network hub VPC and all spoke VPCs</li><li>Restrict the CF Connector security group to egress-only: ports 443 (HTTPS) and 7844 (QUIC) — no inbound rules at all</li><li>Rotate the tunnel secret periodically using Cloudflare’s secret rotation API</li></ul><h3>Conclusion</h3><p>Cloudflare Zero Trust with AWS Transit Gateway provides a production-grade, VPN-free access solution that scales across any number of AWS accounts, environments, and user populations. The key design principles are:</p><ul><li>No inbound ports opened on AWS — the connector pulls the tunnel outward</li><li>Identity, device, and context enforced at the Cloudflare edge before any packet reaches AWS</li><li>Hub-and-spoke TGW routing gives clean isolation between environments with central control</li><li>Everything defined in Terraform — auditable, repeatable, version-controlled</li></ul><p>This architecture is the foundation for a modern SASE deployment. From here you can layer on browser isolation, DLP inspection, CASB for SaaS applications, and cloud email security — all managed from a single Cloudflare Zero Trust dashboard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f8d08f20207" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins CI-CD Setup for deploying terraform(Infra), Docker and Packers]]></title>
            <link>https://medium.com/@awsyadav/jenkins-ci-cd-setup-for-deploying-terraform-infra-docker-and-packers-f7648eb8fc4e?source=rss-5e4b71f714d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7648eb8fc4e</guid>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[aws-ecs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Sandeep Yadav]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 17:21:40 GMT</pubDate>
            <atom:updated>2020-07-31T17:21:40.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*FLLCK00RANOKfclWIlVz0Q.jpeg" /></figure><h3>Introduction</h3><p>This article contains continuous CI-CD deployment of Packers, Terraform and docker which can iterate the product faster.</p><p>As per the above architecture diagram development process would works like:-</p><ul><li>Developer pushes the application code in the Github repository</li><li>Jenkins pipeline would be triggered and will start building the docker image for your apps based on Dockerfile stored on Github</li><li>Docker images will get build, tagged and pushed to ECR repository</li><li>Docker updated image version will get added in ECS task definition and run the updated application</li><li>ECS Cluster Infrastructure would be build using with packer golden Ami image</li></ul><h3>Hands-On: Building a CI/CD Pipeline for Docker, Terraform &amp; Packer</h3><p>Pre-requisites:-</p><ul><li>Installation of Jenkins service</li><li>Installation of Docker service</li><li>Installation of Terraform</li><li>Installation of Packers</li></ul><p>Step 1: Open your terminal in your VM. Start Jenkins and Docker using these commands:</p><pre><em>ysandeep:~ $ sudo service jenkins start<br>Starting Jenkins [ OK ]</em></pre><pre><em>ysandeep:~ $ sudo service jenkins enable</em></pre><pre><em>ysandeep:~ $ sudo service docker start</em></pre><p>Step 2: Open Jenkins on your specified port. click new item</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sARZIl9feAqwWa9r5EhaUw.png" /></figure><blockquote>Docker pipeline</blockquote><p>Step3: Select <strong>pipeline</strong> project and provide the item name &gt;<strong> </strong>create java application jobs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yn9Rv4kFBOgpgsecckYijw.png" /></figure><p>Step 4: Invoke a Jenkinsfile Script (pipeline as a code) -docker apps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFGfL-7ZgFKiD0k64PgsVQ.png" /></figure><p>Step 5: Login to Gitlab &gt; push the java application &gt; Add Dockerfile &amp; Jenkinsfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WSczD3lua5xVcVsuituc_g.png" /></figure><p>Dockerfile:- Creating a docker image of java application</p><p><strong>Jenkinsfile.ui </strong>:- We have used this Pipeline as a code for building the docker image and pushing the image on docker registry also updating the ECS task definition with updated image version</p><p>Jenkinsfile for application deployment</p><blockquote>Terraform pipeline</blockquote><p>Step6: Select new <strong>pipeline</strong> project for infrastructure deployment — Terraform</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLLRrrvMc07EVjQPvH46AA.png" /></figure><p>Step 7: Invoke a Jenkinsfile Script (pipeline as a code)- Infrastructure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVf7iy6xFNAPYHl9aj6-DA.png" /></figure><p>Step 8: Login to Gitlab &gt; push the Terraform code &amp; Jenkinsfile.infra</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSH6XJzWpiDP2f11Alky5A.png" /></figure><p><strong>Jenkinsfile.infra</strong>:- We have used this Pipeline as a code for deploying the infrastructure with terraform i.e terraform init, terraform plan, terraform apply, terraform destroy</p><p>I have already posted the ECS-EC2-Type Deployments with Terraform . Kindly refer the same for infrastructure code:-</p><p><a href="https://medium.com/@awsyadav/automating-ecs-ec2-type-deployments-with-terraform-569863c60e69">Automating ECS-EC2-Type Deployments with Terraform</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7648eb8fc4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating ECS-EC2-Type Deployments with Terraform]]></title>
            <link>https://medium.com/@awsyadav/automating-ecs-ec2-type-deployments-with-terraform-569863c60e69?source=rss-5e4b71f714d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/569863c60e69</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[hashicorp]]></category>
            <dc:creator><![CDATA[Sandeep Yadav]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 08:58:01 GMT</pubDate>
            <atom:updated>2019-07-11T08:58:01.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*pZv_An9DkH27fTKIze8hqA.jpeg" /></figure><h3><strong>AWS Elastic Container Service (ECS)</strong></h3><p>ECS is Amazon’s Elastic Container Service. That’s greek for how you get docker containers running in the cloud. It’s sort of like Kubernetes</p><p>Amazon Elastic Container Service (Amazon ECS) is a scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS. ECS eliminates the need for you to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those virtual machines</p><h4>On this page:-</h4><ul><li>Creating ECR registry for storing the docker image</li><li>Creating Dockerfile and building the image</li><li>Creating terraform code for IAM role</li><li>Creating tf file for ECS-EC2-instance</li><li>Creating ECS Task Definition</li><li>Creating ECS Service</li><li>Creating Application Load Balancer</li><li>Creating Route 53 hosted zone</li><li>Creating cloudwatch log group</li><li>Creating terraform code for IAM role</li></ul><h4>ECR Registry:-</h4><p>Creating Terraform code for ECR repository</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be553ead1070515ea6953e141d6bd4ec/href">https://medium.com/media/be553ead1070515ea6953e141d6bd4ec/href</a></iframe><p>Creating a Docker file and build the image with below command</p><p>-Note*- Make sure you have made the connection with awscli:- <strong>aws configure</strong></p><pre>- docker build -t swagger .</pre><pre>- docker tag swagger:latest xxxxxAWS-ACCOUNT-NOXX.dkr.ecr.eu-west-1.amazonaws.com/swagger:latest</pre><pre>- docker push xxxxxAWS-ACCOUNT-NOXX.dkr.ecr.eu-west-1.amazonaws.com/swagger:latest</pre><p>Dockerfile:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dce44610a91716530449bd5ae39832c0/href">https://medium.com/media/dce44610a91716530449bd5ae39832c0/href</a></iframe><h4>Creating an IAM role and assigning Policy<strong>:-</strong></h4><p>Roles are a really brilliant part of the aws stack. Inside of IAM or identity access and management, you can create roles. These are collections of privileges. I’m allowed to use this S3 bucket, but not others. I can use EC2, but not Athena. And so forth. There are some special policies already created just for ECS and you’ll need roles to use them.</p><p>These roles will be applied at the instance level, so your ecs host doesn’t have to pass credentials around</p><ul><li>ecs-instance-role</li><li>ecs-service-role</li><li>ecs-instance-profile</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfc40d4476140a1849a3397733b77705/href">https://medium.com/media/bfc40d4476140a1849a3397733b77705/href</a></iframe><h4>Elastic container service (ECS-EC2-Type):-</h4><p>Here we are going to create the ECS cluster with launch type as EC2-TYPE. This involves the following resource.</p><ol><li>ECS-Cluster.tf</li><li>ECS-ec2-instance.tf</li><li>ECS-task-defination.tf</li><li>ECS-services.tf</li><li>ECS-ALB.tf</li><li>ECS-cloudwatch.tf</li><li>ECS-Route53.tf</li></ol><h4>ECS-Cluster.tf:-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5abbc1f0c30c1f5ca735d2f9bb998bd6/href">https://medium.com/media/5abbc1f0c30c1f5ca735d2f9bb998bd6/href</a></iframe><h4>ECS-ec2-instance.tf :-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d66f7df764b990bf3437ddc3a7c943/href">https://medium.com/media/b3d66f7df764b990bf3437ddc3a7c943/href</a></iframe><p>user_data.tpl</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fafab59bf9fdbc16e0d15105116f6f1/href">https://medium.com/media/4fafab59bf9fdbc16e0d15105116f6f1/href</a></iframe><h4>ECS-task-defination.tf:-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ae05776011aa31e92ab6f0c1d7df82d/href">https://medium.com/media/1ae05776011aa31e92ab6f0c1d7df82d/href</a></iframe><p>task_definition_json:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccf643517174e0e44a2ac2ba913a2fa8/href">https://medium.com/media/ccf643517174e0e44a2ac2ba913a2fa8/href</a></iframe><h4>ECS-services.tf :-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29d4a66d45438b3a4b0b1f4503a16aee/href">https://medium.com/media/29d4a66d45438b3a4b0b1f4503a16aee/href</a></iframe><h4>ECS-ALB.tf:-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/baccde9de25a001bdf2be51ef52bfac7/href">https://medium.com/media/baccde9de25a001bdf2be51ef52bfac7/href</a></iframe><h4>ECS-cloudwatch.tf:-</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f860589c972f233311d5a043a879ca0b/href">https://medium.com/media/f860589c972f233311d5a043a879ca0b/href</a></iframe><h4><strong>ECS-Route53.tf:-</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a7aec6f0f5c02c8c22610461d522921/href">https://medium.com/media/4a7aec6f0f5c02c8c22610461d522921/href</a></iframe><h4>Running the Terraform script</h4><p>Go to the project folder and type “terraform plan” , this command will show you what you will be creating in the AWS.</p><p>Then you can validate the terraform code with “terraform validate”</p><p>Finally, deploy the resource with “terraform apply”</p><p>And thats it! After our resources are provisioned, we can visit our EC2 Dashboard, find our Load Balancer URL and visit the site running on our newly deployed ECS cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77sRKx8hLDAi7IzRmv67vQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=569863c60e69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Execute Lambda Functions on S3 Event Triggers]]></title>
            <link>https://medium.com/@awsyadav/execute-lambda-functions-on-s3-event-triggers-c0193929f17e?source=rss-5e4b71f714d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0193929f17e</guid>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Sandeep Yadav]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 03:21:13 GMT</pubDate>
            <atom:updated>2019-07-11T03:21:13.677Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A User performing activity by uploading image &gt; S3 notification event get generated &gt; Lambda function get triggered" src="https://cdn-images-1.medium.com/max/492/1*toe-snbPEXoAa2c_8bZb7A.jpeg" /><figcaption>S</figcaption></figure><p>Amazon S3 service is used for file storage, where you can upload or remove files. We can trigger AWS Lambda on S3 when there are any file uploads in S3 buckets. AWS Lambda has a handler function which acts as a start point for AWS Lambda function. The handler has the details of the events. let us see how to use AWS S3 to trigger AWS Lambda function when we upload files in <strong>S3 bucket.</strong></p><p>Refer below repository for accessing the terraform code:-</p><p><a href="https://github.com/awsyadav/Serverless_lambda-function_with_lambda_layer/tree/master/serverless_lambda_s3invoke">awsyadav/Serverless_lambda-function_with_lambda_layer</a></p><h3>Steps for Using AWS Lambda Function with Amazon S3</h3><p>To start using AWS Lambda with Amazon S3, we need the following −</p><ul><li>Create S3 Bucket</li><li>Create role which has permission to work with s3 and lambda</li><li>Create lambda function and add s3 as the trigger.</li></ul><p>Main.tf</p><pre>################</pre><pre># Creating resource variable</pre><pre>################<br>variable &quot;function_name&quot; {}<br>variable &quot;handler_name&quot; {}<br>variable &quot;runtime&quot; {}<br>variable &quot;timeout&quot; {}</pre><pre>###############<br># fetching current account id<br>###############<br>data &quot;aws_caller_identity&quot; &quot;current&quot; {}</pre><pre><br>###############<br># Creating Lambda resource<br>################</pre><pre>resource &quot;aws_lambda_function&quot; &quot;test_lambda&quot; {<br>function_name    = &quot;${var.function_name}&quot;<br>role             = &quot;arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/AWSRoleForLambda&quot;<br>handler          = &quot;${var.handler_name}.lambda_handler&quot;<br>runtime          = &quot;${var.runtime}&quot;<br>timeout          = &quot;${var.timeout}&quot;<br>filename         = &quot;${var.handler_name}.zip&quot;<br>source_code_hash = &quot;${base64sha256(file(&quot;${var.handler_name}.zip&quot;))}&quot;<br>environment {<br>   variables = {<br>    CreatedBy = &quot;Terraform&quot;}<br>}<br>}</pre><pre>##################<br># Creating s3 resource for invoking to lambda function<br>##################</pre><pre>resource &quot;aws_s3_bucket&quot; &quot;bucket&quot; {<br>bucket = &quot;my-test-bucket-eu-west-1&quot;<br>acl    = &quot;private&quot;<br>tags = {<br>Name        = &quot;My bucket&quot;<br>Environment = &quot;Dev&quot;<br>}<br>}</pre><pre>##################<br># Adding S3 bucket as trigger to my lambda and giving the permissions<br>##################</pre><pre>resource &quot;aws_s3_bucket_notification&quot; &quot;aws-lambda-trigger&quot; {<br>bucket = &quot;${aws_s3_bucket.bucket.id}&quot;<br>lambda_function {<br>lambda_function_arn = &quot;${aws_lambda_function.test_lambda.arn}&quot;<br>events              = [&quot;s3:ObjectCreated:*&quot;]<br>filter_prefix       = &quot;file-prefix&quot;<br>filter_suffix       = &quot;file-extension&quot;<br>}<br>}</pre><pre>resource &quot;aws_lambda_permission&quot; &quot;test&quot; {<br>statement_id  = &quot;AllowS3Invoke&quot;<br>action        = &quot;lambda:InvokeFunction&quot;<br>function_name = &quot;${aws_lambda_function.test_lambda.function_name}&quot;<br>principal = &quot;s3.amazonaws.com&quot;<br>source_arn = &quot;arn:aws:s3:::${aws_s3_bucket.bucket.id}&quot;<br>}</pre><pre>###########<br># output of lambda arn<br>###########</pre><pre>output &quot;arn&quot; {<br>value = &quot;${aws_lambda_function.test_lambda.arn}&quot;<br>}</pre><p>terraform.tfvars &gt; contain all the variables values</p><pre>function_name = &quot;test-lambda_function-name&quot;<br>handler_name  = &quot;lambda_function&quot;<br>runtime       = &quot;python3.6&quot;<br>timeout       = &quot;900&quot;</pre><p>Now save this file &gt; use provider .tf file with access key and secret key of your account</p><pre>provider &quot;aws&quot; {<br>region = &quot;eu-west-1&quot;<br>access_key  = &quot;&quot;<br>ecret_key  = &quot;&quot;<br>}</pre><ul><li>terraform plan</li><li>terraform apply</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0193929f17e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>