How adrianojiu/cloudfront_add_ranges_security_group_auto_lambda works
Project Type and Purpose
• This is a serverless, event-driven utility that automatically updates a Security Group with AWS CloudFront IP ranges.
• It uses AWS services (SNS, Lambda, EC2 APIs, S3) and Infrastructure-as-Code (CloudFormation) to deploy and manage resources.
Main Components
a. AWS Services
• SNS Topic: AmazonIpSpaceChanged (publishes IP range change events)
• Lambda Function: Python 3.9 handler (sg-cloudfront-global-edge-ips-rule-lambda.py)
• IAM Role & Policy: Grants Lambda permissions to describe/update security groups
• EC2 Security Group: Holds CloudFront IP rules (updated by Lambda)
• S3 Bucket: Hosts sg_lambda.zip code bundle
• CloudFormation: Template (cloudformation_create_lambda_function.json) to provision Lambda, IAM, SNS subscription
b. Optional Manual Invocation
• AWS CLI: aws lambda invoke to manually trigger the Lambda
Relationships and Data Flows
• CloudFormation → creates IAM Role, Lambda Function, SNS Subscription
• S3 Bucket (sg_lambda.zip) → Lambda function code at deployment
• SNS Topic → invokes Lambda whenever AWS publishes new IP ranges
• Lambda Function → uses IAM Role to call EC2 APIs → adds/removes rules on the Security Group
• (Optional) AWS CLI → calls Lambda handler endpoint directly
Architectural Patterns and Principles
• Event-Driven Architecture: SNS → Lambda on IP-change events
• Serverless / FaaS: No long-running servers, pay per execution
• Infrastructure as Code: All AWS resources can be deployed via CloudFormation
• Idempotent Operations: Lambda checks for existing rules before creation
• Inside, list the three resources it creates: IAM Role, Lambda Function (with link to S3), SNS Subscription
Final Touches
• Component has a clear label.
• Arrowheads indicating flow direction.
• Related services into logical zones (e.g., “AWS Control Plane”, “Serverless Runtime”, “Networking”).