/aws-automation-with-lambda

Automating AWS with Lambda, Python, and Boto3

Primary LanguageHCL

Automating AWS with Lambda, Python, and Boto3

Create CloudWatch rule for `CreateVpc` API call.
Navigate to CloudWatch.
    Click Create rule.
    Select Event Pattern.
    Service Name: EC2
    Event Type: AWS API Call via CloudTrail
    Specific Operation: "CreateVpc"
    Note that eventName sets CreateVpc in the preview
    Click Add target.
    Select Lambda function EnableVpcFlowLogs.
    Click Configure details.
------------------------------------------------
Create a VPC, and check the Flow Logs was enable.
  • Virtual environment
  • Create Virtual env: python3 -m venv venv
  • source venv/bin/activate
  • pip install --upgrade pip
  • pip install -r requirements.txt
  • Terraform commands
  • export TF_PATH=
  • terraform -chdir=${TF_PATH} init
  • terraform -chdir=${TF_PATH} plan -var=name=
  • terraform -chdir=${TF_PATH} apply -var=name=
  • Invoking aws lambda using aws cli:
export NAME=<lambda name>
aws lambda invoke --invocation-type Event \
  --function-name ${NAME} \
  --invocation-type Event \
  --payload '{}' \
  response.json

Reference: