This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import json | |
import csv | |
import datetime | |
from pkg_resources import resource_filename | |
ReportFile = './report.csv' | |
CpuThreshold = 40 # If we reduce instance size, CPU utilization will be twice. e.g. 40*2=80% CPU utilization | |
# EC2 filter, we will skip terminated instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
properties([ | |
parameters([ | |
choice( | |
name: 'PYTHON', | |
description: 'Choose Python version', | |
choices: ["python2.7", "python3.6", "python3.7", "python3.8", "python3.9"].join("\n") | |
), | |
base64File( | |
name: 'REQUIREMENTS_FILE', | |
description: 'Upload requirements file (Optional)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from datetime import datetime | |
import sys | |
import boto3 | |
import botocore | |
import urllib.request | |
ec2 = boto3.client('ec2', region_name='eu-west-1') | |
def create_snapshot(app): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": [ | |
"ec2:AttachNetworkInterface", | |
"ec2:DetachNetworkInterface", | |
"ec2:DescribeInstances", | |
"ec2:DescribeNetworkInterfaces", | |
"ec2:AssignPrivateIpAddresses", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Id": "certbot-dns-route53", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"route53:ListHostedZones", | |
"route53:GetChange" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
custom_ec2_filter = [ | |
{ | |
'Name': 'instance-state-name', | |
'Values': ['running', 'pending'] | |
} | |
] | |
# Combination of tag key and value to prevent shutdown/downscale resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Description: 'Template for Lambda Fuction for stopping AWS resources (EC2, RDS, ASG)' | |
### OUTPUT ### | |
Outputs: | |
LambdaRoleARN: | |
Description: Role for Lambda execution. | |
Value: | |
Fn::GetAtt: | |
- LambdaRole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import boto3 | |
def cleanup(): | |
get_last_modified = lambda obj: int(obj['LastModified'].strftime('%s')) | |
s3 = boto3.client('s3') | |
result = s3.list_objects(Bucket=bucket, Delimiter='/') | |
for dir in result.get('CommonPrefixes'): | |
print('Directory: ' + str(dir['Prefix'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage("Send notification") { | |
steps { | |
script { | |
withCredentials([string(credentialsId: 'slack-app', variable: 'slack_token')]) { | |
env.SLACK_USER_ID = sh (script: """ | |
SLACK_USER_ID="\$(curl -d \"token=${slack_token}\" -d \"email=${env.AUTHOR_EMAIL}\" https://slack.com/api/users.lookupByEmail | jq -r '.user.id')" | |
echo \$SLACK_USER_ID""", returnStdout: true).trim() | |
} | |
if ("${env.PULL_REQUEST_COMMENT_COUNT}" == "0") { | |
sendBitbucketComment ("${env.REPO_FULL_NAME}", "${env.PULL_REQUEST_ID}", "${env.WELCOME_COMMENT}") |
OlderNewer