Skip to content

Instantly share code, notes, and snippets.

@skbali
skbali / handler.py
Last active May 8, 2021 15:11
sitemonitor-iac-serverless
import json
import requests
import time
import datetime
import boto3
from boto3.dynamodb.conditions import Key
from boto3.dynamodb.conditions import Attr
# AWS Resource and Client
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
@skbali
skbali / aws-dynamodb-gsi.json
Created May 8, 2021 13:48
sitemonitor-iac-script
[
{
"IndexName": "siteStatus-site-Index",
"KeySchema": [
{
"AttributeName": "siteStatus",
"KeyType": "HASH"
},
{
"AttributeName": "site",
@skbali
skbali / main.auto.tfvars
Last active September 20, 2022 07:17
GCP Storage Bucket with CMK
key_name = "key-sbali"
keyring_name = "keyring-sbali"
region = "us-central1"
bucket_name = "sbali-storage"
@skbali
skbali / handler.py
Last active June 14, 2020 19:50
Set CloudWatch Log Retention using Lambda Function
import json
import boto3
cwl = boto3.client('logs')
def logretention(event, context):
'''
Method invoked by AWS to start the function
'''
token = None
@skbali
skbali / Dockerfile
Created May 24, 2020 14:54
Build and Push Docker image to Amazon ECR
FROM nginx:latest
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
@skbali
skbali / data.tf
Last active June 17, 2022 14:08
KMS-S3
data "aws_caller_identity" "current" {}
#!/bin/sh -x
sudo sh -c 'apt-get update -y'
sudo sh -c 'apt-get upgrade -y'
service: ecslogger # NOTE: update this with your service name
provider:
name: aws
runtime: python3.7
environment:
DYNAMODB_TABLE: ${self:service}
stage: prd
iamRoleStatements:
@skbali
skbali / handler.py
Created January 27, 2020 04:21
serverless - asg ec2 age check
import boto3
import time
import json
from datetime import datetime, timedelta, timezone
asgclient = boto3.client('autoscaling')
ec2client = boto3.client('ec2')
def asg_ec2_age_check(event, context):
'''
@skbali
skbali / serverless.yml
Created January 27, 2020 04:20
serverless - asg ec2 age check
service: asgec2agecheck # NOTE: update this with your service name
provider:
name: aws
runtime: python3.7
deploymentBucket: sbali-serverless-us
tags:
CostCenter: infra
stage: prd
iamRoleStatements: