Skip to content

Instantly share code, notes, and snippets.

Avatar

quiver

View GitHub Profile
@quiver
quiver / set-retention-for-lambda-at-edge-logs.sh
Created May 9, 2020
Bash Script to set retention periods for Lambda@Edge CloudWatch Logs in all regions.
View set-retention-for-lambda-at-edge-logs.sh
#!/bin/bash
# L@E logs are displayed or stored in the Region closest to the location where the function executed.
# This Bash script sets retention periods for CloudWatch Log in all regions.
FUNCTION_NAME=LambdaAtEdgeFunctionName
LOG_GROUP=/aws/lambda/us-east-1.${FUNCTION_NAME}
# Possible Values: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653.
RETENTION_IN_DAYS=30
@quiver
quiver / boto3_cloudfront_create_invalidation.py
Created Mar 14, 2020
Sample script to create CloudFront invalidation
View boto3_cloudfront_create_invalidation.py
'''
Invalidate Amazon CloudFront paths
API
- https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateInvalidation.html
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudfront.html#CloudFront.Client.create_invalidation
'''
import random
import time
import boto3
@quiver
quiver / cloudformation-template-for-aws-backup-thin-backups.yaml
Created Jul 20, 2019
CloudFormation template to configure thin backup rules for AWS Backup
View cloudformation-template-for-aws-backup-thin-backups.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: "Backup Plan template for thin backups"
Resources:
BackupVaultWithThinBackups:
Type: "AWS::Backup::BackupVault"
Properties:
BackupVaultName: "BackupVaultWithThinBackups"
BackupPlanWithThinBackups:
Type: "AWS::Backup::BackupPlan"
@quiver
quiver / eic-cli.sh
Last active Apr 12, 2021
simple shell script to demonstrate how EC2 Instance Connect CLI is implemented
View eic-cli.sh
#!/bin/bash
# simple shell script to demonstrate how EC2 Instance Connect CLI is implemented.
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html
#
# Usage
# $ bash eic-cli.sh i-1234
if [ $# -ne 1 ]; then
echo "Usage"
echo "$ bash eic-cli.sh i-1234"
@quiver
quiver / iam-policy.json
Last active Jul 7, 2021
How to connect to Amazon RDS PostgreSQL with IAM credentials
View iam-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:region:account-id:dbuser:dbi-resource-id/database-user-name"
@quiver
quiver / athena.py
Last active Apr 29, 2021
query SQL to Amazon Athena and save its results from Amazon S3 Raw
View athena.py
#!/usr/bin/env python
# vim: set fileencoding=utf8 :
```
$ pip install -U boto3 retrying
$ export AWS_DEFAULT_PROFILE=test
$ cat foo.sql
select count(*)
from bar
$ python athena.py foo.sql
$ ls -1
@quiver
quiver / kinesis-stream-state-diagram.dot
Last active May 8, 2016
AWS Kinesis Stream Status Diagram created with Graphviz
View kinesis-stream-state-diagram.dot
// $ dot -Tpng kinesis-stream-state-diagram.dot -o kinesis-stream-state-diagram.png
digraph kinesis_stream_status {
labelloc="t";
label="AWS Kinesis Streams : Stream State Diagram";
CreateStream[shape=box];
DeleteStream[shape=box];
MergeShards[shape=box];
SplitShards[shape=box];
IncreaseStreamRetentionPeriod[shape=box];
@quiver
quiver / sample-output-of-describe-auto-scaling-groups.json
Created Feb 28, 2016
aws : autoscaling waiters based on aws/aws-sdk-ruby
View sample-output-of-describe-auto-scaling-groups.json
{
"AutoScalingGroups": [
{
"AutoScalingGroupARN": "arn:aws:autoscaling:ap-northeast-1:123456789012:autoScalingGroup:aaaaaaaa-35cb-4f11-bf21-258b69e3c42d:autoScalingGroupName/bar",
"HealthCheckGracePeriod": 300,
"SuspendedProcesses": [],
"DesiredCapacity": 0,
"Tags": [],
"EnabledMetrics": [],
"LoadBalancerNames": [],
@quiver
quiver / lambda.py
Created Dec 15, 2015
Store SORACOM Air traffic to Elasticsearch Raw
View lambda.py
# API https://dev.soracom.io/jp/docs/api/#!/Stats/get_stats_air_subscriber
"""
AWS Lambda function to retrieve traffic data from SORACOM and store them to Elasticsearch
"""
import datetime
import json
import requests
SORACOM_EMAIL="dummy@example.com"
@quiver
quiver / retrieve-EC2-region-information-from-metadata.md
Last active May 11, 2021
retrieve EC2's region from instance metadata
View retrieve-EC2-region-information-from-metadata.md

Sometimes you want to retrieve EC2 insntances' region information.

You can query that information through instance metadata(169.254.169.254).

$ curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document
{
  "privateIp" : "172.31.2.15",
  "instanceId" : "i-12341ee8",
  "billingProducts" : null,
  "instanceType" : "t2.small",