n473- / lambda_sgIngress

Lambda function to update EC2 security group ingress rule TCP/22 SSH based on source public IP. Uses MFA and secure request signing to invoke API Gateway.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Updating EC2 security groups with Lambda

##sg_ingress_lambda.py

The Lambda function that integrates with API Gateway. Inherits VPC and Security Group IDs from URL query string parameters via API Gateway context object mapping:

{
"pub_ip": "$context.identity.sourceIp",
"vpcid": "$input.params('vpcid')",
"sgid": "$input.params('sgid')"
}

##sg_ingress_client.py

Local script used to assume an IAM role with API Gateway invocation permissions. Uses IAM MFA for initial assume role request. Inherits temporary credentials from assumed role, which are used to sign a GET request sent to the API Gateway endpoint that fires off the Lambda function above.

More information available on my blog

About

Lambda function to update EC2 security group ingress rule TCP/22 SSH based on source public IP. Uses MFA and secure request signing to invoke API Gateway.


Languages

Language:Python 100.0%