This file contains hidden or 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
Parameters: | |
InstanceCount: | |
Description: Number of EC2 instances (must be between 1 and 3). | |
Type: Number | |
Default: 1 | |
MinValue: 1 | |
MaxValue: 3 | |
ConstraintDescription: Must be a number between 1 and 3. | |
Description: launch EC2 instances. | |
InstanceType: |
This file contains hidden or 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 json | |
import cfnresponse | |
import boto3 | |
from botocore.exceptions import ClientError | |
client = boto3.client("logs") | |
def PutPolicy(arn,policyname): | |
response = client.put_resource_policy( | |
policyName=policyname, |
This file contains hidden or 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 | |
cloudtrail = boto3.client('cloudtrail') | |
paginator = cloudtrail.get_paginator('lookup_events') | |
StartingToken = None | |
page_iterator = paginator.paginate( | |
LookupAttributes=[{'AttributeKey':'EventName','AttributeValue': 'RunInstances'}], | |
PaginationConfig={'PageSize':10, 'StartingToken':StartingToken }) |
This file contains hidden or 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: | |
Create Event rule and lambda functions to report for following criteria | |
Idle EC2 instances if CPU < 10% and Network < 5MB | |
RDS Instance with no connections for 7 days | |
ELB with No Active backends and requests below 100 | |
Parameters: | |
LambdaName: | |
Default: AWSReport |
This file contains hidden or 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
# Sublime Plugin created for stackoverflow answer. | |
# https://stackoverflow.com/questions/49213489/sublime-text-and-python-plugin-how-to-incorporate-a-python-code-with-a-for-loop | |
import sublime, sublime_plugin, re, string #import the required modules | |
class ConvertCommand(sublime_plugin.TextCommand): #create Text Command | |
def run(self, edit): #implement run method | |
for region in self.view.sel(): #get user selection | |
if not region.empty(): #if selection not empty then | |
s = self.view.substr(region) #assign s variable the selected region | |
replace = '\n'.join([' '.join(para.splitlines()) for para in s.split('\n\n')]) |
This file contains hidden or 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
# Quick test for https://stackoverflow.com/questions/49163883/sign-in-page-for-aws-federated-login/49212472#49212472 | |
# Ref: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-custom-url.html | |
# python3 run.py | |
import urllib.parse,json | |
import requests # 'pip install requests' | |
from boto.sts import STSConnection # AWS SDK for Python (Boto) 'pip install boto' | |
from flask import Flask,redirect # pip install flask | |
app = Flask(__name__) |
This file contains hidden or 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 | |
from datetime import datetime, timezone | |
from functools import reduce | |
import operator | |
ec2 = boto3.client('ec2') | |
cloudtrail = boto3.client('cloudtrail') | |
def get_events(instanceid): | |
response = cloudtrail.lookup_events ( |
This file contains hidden or 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
## | |
# Python Boto3 script to find the number of minutes an instance has been running. | |
## Output | |
# i-00asdf5xxx50c96aa 84 days, 13:17:51.468559 | |
# i-0260a1fxxx27ec894 6 days, 13:48:04.468643 | |
# i-0acxxx6c630af322 13 days, 12:13:00.468659 | |
# i-069bxxxd41bf975eb 19:42:08.468670 | |
import boto3 | |
from datetime import datetime, timezone |
This file contains hidden or 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
// https://stackoverflow.com/questions/48982349/query-aws-cli-to-populate-jenkins-active-choices-reactive-parameter-linux | |
// Get list of IPS from AWS CLI and populate Active Choices Reactive Parameter | |
def command = 'aws ec2 describe-instances --filters Name=tag:Name,Values=Test --query Reservations[*].Instances[*].PrivateIpAddress --output text' | |
def proc = command.execute() | |
proc.waitFor() | |
def output = proc.in.text | |
def exitcode= proc.exitValue() | |
def error = proc.err.text |
This file contains hidden or 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' | |
Resources: | |
EnableLogs: | |
Type: Custom::EnableLogs | |
Version: '1.0' | |
Properties: | |
ServiceToken: arn:aws:lambda:us-east-1:acc:function:rds-EnableRDSLogs-1O6XLL6LWNR5Z | |
DBInstanceIdentifier: mydb | |
Outputs: |
NewerOlder