Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am antonioned on github.
  • I am antonioned (https://keybase.io/antonioned) on keybase.
  • I have a public key ASBZGIT8PmMvElRCaVQ0r2d4PmskIGxFIKSesVkX-2l7rgo

To claim this, I am signing this object:

@antonioned
antonioned / scan-task-definitions.sh
Created November 20, 2019 09:45
Script that scans ECS task definitions for a compromised AWS key. In order to run, it needs a definitions.txt file with ARNs of the task definitions that need scanning.
#!/bin/bash
while read d;
do
printf "\n\nName of task-definition: $d\n\n" >> ./task-definitions-results.txt
aws ecs describe-task-definition --task-definition $d --region us-west-2 | grep "AWS_KEY" >> ./task-definitions-results.txt
printf "\n\n------------------------------------------------\n\n" >> ./task-definitions-results.txt
done < definitions.txt
@antonioned
antonioned / scan-repos.sh
Created November 20, 2019 09:43
Script that uses git secrets command to check fo vulnerabilities in git repos.
#!/bin/bash
for r in REPO1 REPO2 REPO3
do
cd $r
printf "\n\nName of repo: $r\n\n\n" >> ../repos-results.txt
git secrets --scan >> ../results.txt
printf "\n------------------------------------------------\n" >> ../repos-results.txt
cd ../
done
@antonioned
antonioned / Lambda Cloudfront invalidation function
Created November 14, 2019 12:47
Python 2.7 Lambda function that does invalidations invoked by S3 bucket changes
from __future__ import print_function
import boto3
import time
def lambda_handler(event, context):
path = ["/*"]
print(path)
client = boto3.client('cloudfront')
invalidation = client.create_invalidation(DistributionId='ID_OF_THE_DISTRIBUTION',
@antonioned
antonioned / function.js
Last active October 30, 2018 16:44 — forked from vgeshel/function.js
AWS Lambda function for forwarding SNS notifications to Slack
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = process.env.SLACK_WEBHOOK_URL // add the SLACK_WEBHOOK_URL to the env. variables in the Lambda
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
@antonioned
antonioned / Sumologic to EBS integration
Last active October 4, 2018 14:41
Sumologic - Elastic Beanstalk integration
This is the .config file that I am using for installing, configuring and deploying sumologic to Elastic Beanstalk.
The file does all the neccessar changes to the sumologic files in order to install the Collector and start it with the accessid and accesskey that are set up in the Beanstalk env. variables.
After installing is done, all the files are edited so that the collector can use the Local File Configuration and read sources from the dev-sources.json file.
This is the one I am using for dev, the tests in the container command express that. You can set up the ENV_NAME with the name of your Beanstalk environment and run the commands only on the env you need.
A setup-sumo-prod.sh with production values can be set and run only on prod.
@antonioned
antonioned / Codeship CD to EBS
Last active October 4, 2018 14:41
Custom Codeship script for deployment to Elastic Beanstalk
#!/bin/sh
#for app label I am using the last commit on github, but because spaces pose a problem in S3, replace SPACE with an underscore _
export APP_VERSION=`git log --oneline -n 1 | cut -c 1-90 | sed 's/ /_/g'`
pip install awscli
# clean build artifacts and create the application archive (also ignore any files named .git* in any folder)
git clean -fd
# precompile assets, ...
# zip the application
zip -x *.git* -r "${AWS_APP_NAME}-${APP_VERSION}.zip" .
# delete any version with the same name (based on the short revision) - optional
@antonioned
antonioned / Ruby upgrade on AWS EBS
Last active October 4, 2018 14:42
Upgrading AWS Beanstalk Ruby 2.2 environment to Ruby 2.3
Steps I did:
1. Launched a completely new environment on beanstalk running the ruby version that I need, 2.3 (in my case I needed an update from Ruby 2.2 to Ruby 2.3) - used the sample application for faster and easier launch.
2. SSH-ed into the new instance and installed all dependencies that my application needs (packages, dev tools etc.) - you can also do these in the .ebextensions directory
3. Created a custom AMI from the instance running ruby 2.3 with everything installed
4. Used the same command that Rohit posted but with some tweeks:
aws elasticbeanstalk update-environment --region "REGION" --environment-name "ENV_NAME" --solution-stack-name "64bit Amazon Linux 2018.03 v2.8.1 running Ruby 2.3 (Puma)" --option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=ImageId,Value="ami-
xxxxxxxx"