Skip to content

Instantly share code, notes, and snippets.

View koladilip's full-sized avatar

Dilip Kola koladilip

View GitHub Profile
@koladilip
koladilip / policy.json
Last active April 3, 2020 09:39
Cognito Identity Pool Authenticated Role Policy to Upload to S3 bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
@koladilip
koladilip / s3-bucket-policy-for-static-web-hosting.json
Created June 21, 2018 06:13
S3 bucket policy for hosting a static website directly from S3
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow Public Access to All Objects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<www.mywebsite.com>/*"
}
'use strict';
const AWS = require("aws-sdk");
const dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context, callback) => {
const contactInfo = {};
contactInfo.Item = {
"email": event.email,
"name": event.name,
"message": event.message
};
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "mywebsiteContactUsTableWrite",
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"dynamodb:UpdateItem"
],
{
"swagger": "2.0",
"info": {
"title": "mywebsite"
},
"paths": {
"/contact-us": {
"post": {
"produces": [
"application/json"
aws rds create-db-parameter-group --db-parameter-group-name replication --db-parameter-group-family MySQL5.7 --description "My DB params for replication"
aws rds modify-db-parameter-group --db-parameter-group-name mydbparametergroup --parameters "ParameterName=binlog_format,ParameterValue=ROW,ApplyMethod=immediate"
aws rds modify-db-instance --db-instance-identifier myMasterDBInstance --db-parameter-group-name replication
# Wait for sometime so that instance finish modification and then reboot the instance.
aws rds reboot-db-instance --db-instance-identifier myMasterDBInstance
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow Public Access to All Objects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<www.mywebsite.com>/*"
}
@koladilip
koladilip / cloudwatch-log-lambda-export-policy.json
Created June 21, 2018 10:13
Policy for Lambda function to export Cloudwatch logs to S3
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"logs:CreateExportTask",
"logs:DescribeExportTasks",
"logs:DescribeLogGroups"
@koladilip
koladilip / cloudwatch_logs.js
Created June 21, 2018 10:26
Cloudwatch Logs to S3 exporter AWS Lambda function code
const AWS = require('aws-sdk');
const cloudwatchLogs = new AWS.CloudWatchLogs();
function getDatePath(date) {
date = date || new Date();
const dateString = date.toISOString().substring(0, 10);
return dateString.replace(/-/g, '/');
}
function getLogPathForS3(logGroupName) {
@koladilip
koladilip / step-function-state-machine.json
Created June 21, 2018 10:40
State machine definition for step function to export cloudwatch logs to S3 using lambda: https://gist.github.com/koladilip/780643318b5fba48abc026d9992d8e36
{
"Comment": "Cloudwatch logs to S3 export task",
"StartAt": "CreateExportTask",
"States": {
"CreateExportTask": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:<awws-account-id>:function:CloudwatchLogsToS3Exporter",
"Next": "IsAllLogsExported"
},
"IsAllLogsExported": {