Skip to content

Instantly share code, notes, and snippets.

View sudheerchamarthi's full-sized avatar

Sudheer Chamarthi sudheerchamarthi

View GitHub Profile
import boto3
s3_client = boto3.client('s3')
ec2_client = boto3.client('ec2', region_name="us-east-1")
import pprint
# Use this website for Json - https://jsoneditoronline.org/
# s3_response = s3_client.create_bucket(
# Bucket='mys3bucket-tyuihgfdsrtyuikjhabc',
# )
#
# if s3_response["ResponseMetadata"]["HTTPStatusCode"] == "200":
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'I am creating 2 s3 buckets and an EC2 instance'
Mappings:
RegionAMI:
us-east-1:
al2: ami-0022f774911c1d690
ubuntu: ami-09d56f8956ab235b3
redhat: ami-0f095f89ae15be883
us-east-2:
---
- name: Check if {{ packageName }} is installed
stat: path=/var/www/html2
register: app_path
tags: instal
- name: Install {{ packageName }}
block:
- include: install.yml
when: app_path.stat.exists and ansible_distribution == "Amazon"
import boto3
import json
sts=boto3.client('sts')
crossRoleArn = "arn:aws:iam::XX:role/cross"
stsresponse = sts.assume_role(RoleArn=crossRoleArn,RoleSessionName='dynamocross')
src_client = boto3.client('dynamodb', region_name="us-east-1")
dest_client = boto3.client('dynamodb', region_name="us-east-1",aws_access_key_id=stsresponse["Credentials"]["AccessKeyId"],aws_secret_access_key=stsresponse["Credentials"]["SecretAccessKey"],aws_session_token=stsresponse["Credentials"]["SessionToken"])
srcTableName="src"
import boto3
# Change this - Add the Tag Key to look for in ASG
asgStopTagKey = "status"
# Change this - Add the Tag Value to look for in ASG
asgStopTagValue = "off"
asgDesiredCount = 0
asgMinValue = 0
# Change this - Add the Tag Key to look for in EC2
ec2StopTagKey = "status"
# Change this - Add the Tag Value to look for in EC2
import boto3
client = boto3.client('elbv2',region_name='us-east-1')
elb = client.describe_load_balancers()
for lb in range(len(elb['LoadBalancers'])):
ALBName = elb['LoadBalancers'][lb]['LoadBalancerName']
ALBArn = elb['LoadBalancers'][lb]['LoadBalancerArn']
if elb['LoadBalancers'][lb]['Type'] == "application":
elblistener = client.describe_listeners(LoadBalancerArn=elb['LoadBalancers'][lb]['LoadBalancerArn'])
try:
SSLPolicy = elblistener['Listeners'][0]['SslPolicy']
import boto3
import datetime
import time
ec2 = boto3.client('ec2', region_name='us-east-1')
instances=ec2.describe_instances()
cloudwatch = boto3.client('cloudwatch')
for instance in range(len(instances['Reservations'])):
instanceID=instances['Reservations'][instance]['Instances'][0]['InstanceId']
instanceType = instances['Reservations'][instance]['Instances'][0]['InstanceType']
for tag in instances['Reservations'][instance]['Instances'][0]['Tags']:
import boto3
from datetime import datetime, timedelta
import time
client = boto3.client('ec2', region_name='us-east-1')
ec2Usedamis = client.describe_instances()
ec2UsedamiList=[]
oldamilist = []
for ec2ami in range(len(ec2['Reservations'])):
ec2UsedamiList.append(ec2['Reservations'][ec2ami]['Instances'][0]['ImageId'])
createdAMI = client.describe_images(Owners=['self'])
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-iam-test
namespace: demo
spec:
replicas: 1
selector:
matchLabels:
app: eks-iam-test
apiVersion: v1
kind: ServiceAccount
metadata:
name: demo
namespace: demo
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::11111111:role/rolename