From a73f9f6e47a26a306778a39e9adbb47f2fddbd66 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Sun, 6 Oct 2019 20:45:15 +0530 Subject: [PATCH 01/18] Update Readme.md Maile me added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fbc1b1..dd18ddb 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ tag_ec2_vol_csv.py | Tag volumes based on csv input file, csv file format, "Volu ### License GNU General Public License v3.0 -Mail: sureshvenkey@gmail.com +Mail Me: sureshvenkey@gmail.com Website: www.sureshvenkey.com From 4371235f99983153d245ead7081b6f0dc1279f82 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Mon, 7 Oct 2019 09:13:17 +0530 Subject: [PATCH 02/18] Updated security groups in inventroy Updated security groups in inventroy --- ...es_and_volumes.py => inventory_ec2_vol_sg.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) rename inventory_ec2_instances_and_volumes.py => inventory_ec2_vol_sg.py (81%) diff --git a/inventory_ec2_instances_and_volumes.py b/inventory_ec2_vol_sg.py similarity index 81% rename from inventory_ec2_instances_and_volumes.py rename to inventory_ec2_vol_sg.py index 7777653..f1ea339 100644 --- a/inventory_ec2_instances_and_volumes.py +++ b/inventory_ec2_vol_sg.py @@ -1,5 +1,5 @@ ''' -Creates inventory file ec2 instances and volumes in current working +Creates inventory file ec2 instances, volumes & security group in current working directory. file name as follows ec2_instances_inv.csv, ec2_volumes_inv.csv Created on 02-Oct-2019 @@ -20,7 +20,7 @@ for each_in in ec2_re.instances.all(): csv_w.writerow([S_No,each_in.ami_launch_index, each_in.architecture, each_in.block_device_mappings, each_in.capacity_reservation_id, each_in.capacity_reservation_specification, each_in.classic_address, each_in.client_token, each_in.cpu_options, each_in.ebs_optimized, each_in.elastic_gpu_associations, each_in.elastic_inference_accelerator_associations, each_in.ena_support, each_in.hibernation_options, each_in.hypervisor, each_in.iam_instance_profile, each_in.id, each_in.image, each_in.image_id, each_in.instance_id, each_in.instance_lifecycle, each_in.instance_type, each_in.kernel_id, each_in.key_name, each_in.key_pair, each_in.launch_time, each_in.licenses, each_in.meta, each_in.monitoring, each_in.network_interfaces, each_in.network_interfaces_attribute, each_in.placement, each_in.placement_group, each_in.platform, each_in.private_dns_name, each_in.private_ip_address, each_in.product_codes, each_in.public_dns_name, each_in.public_ip_address, each_in.ramdisk_id, each_in.root_device_name, each_in.root_device_type, each_in.security_groups, each_in.source_dest_check, each_in.spot_instance_request_id, each_in.sriov_net_support, each_in.state, each_in.state_reason, each_in.state_transition_reason, each_in.subnet, each_in.subnet_id, each_in.tags, each_in.virtualization_type, each_in.volumes, each_in.vpc, each_in.vpc_addresses, each_in.vpc_id]) S_No=S_No+1 -print ("Inventory file created - ec2_instances_inv.csv") +print ("EC2 Inventory file created - ec2_instances_inv.csv") ec2invfile.close() vol_header_csv=['S_No', 'attachments', 'availability_zone', 'create_time', 'encrypted', 'id', 'iops', 'kms_key_id', 'meta', 'size', 'snapshot_id', 'snapshots', 'state', 'tags', 'volume_id', 'volume_type'] @@ -31,5 +31,16 @@ for each_ec2_vol in ec2_re.volumes.all(): csv_w.writerow([S_No, each_ec2_vol.attachments, each_ec2_vol.availability_zone, each_ec2_vol.create_time, each_ec2_vol.encrypted, each_ec2_vol.id, each_ec2_vol.iops, each_ec2_vol.kms_key_id, each_ec2_vol.meta, each_ec2_vol.size, each_ec2_vol.snapshot_id, each_ec2_vol.snapshots, each_ec2_vol.state, each_ec2_vol.tags, each_ec2_vol.volume_id, each_ec2_vol.volume_type]) S_No=S_No+1 -print ("Inventory file created - ec2_volumes_inv.csv") +print ("Volume Inventory file created - ec2_volumes_inv.csv") volinvfile.close() + +sg_header_csv=['S_No', 'security_group_id', 'description', 'group_id', 'group_name', 'ip_permissions', 'ip_permissions_egress', 'owner_id', 'tags', 'vpc_id'] +S_No=1 +sginvfile=open("ec2_sg_inv.csv","w", newline='') +csv_w=csv.writer(sginvfile) +csv_w.writerow(sg_header_csv) +for each_ec2_sg in ec2_re.security_groups.all(): + csv_w.writerow([S_No, each_ec2_sg.id, each_ec2_sg.description, each_ec2_sg.group_id, each_ec2_sg.group_name, each_ec2_sg.ip_permissions, each_ec2_sg.ip_permissions_egress, each_ec2_sg.owner_id, each_ec2_sg.tags, each_ec2_sg.vpc_id]) + S_No=S_No+1 +print ("Security Group Inventory file created - ec2_sg_inv.csv") +sginvfile.close() From 11160dd2275752c76948fabe73e659ea9b99648a Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Mon, 7 Oct 2019 09:14:19 +0530 Subject: [PATCH 03/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd18ddb..11e1108 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ C:\Users\venkatraj\Desktop\boto3> Code Name | Description ----------|------------- delete_ec2_unused_vol.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags. -inventory_ec2_instances_and_volumes.py | Creates a inventory in the form of csv file in the current location for ec2 instances and volumes for a specified region. +inventory_ec2_vol_sg.py | Creates a inventory in the form of csv file in the current location for ec2 instances, volumes and security group for a specified region. list_ec2_volumes_with_boto3_filters.py | How to use boto3 filter for tags list_ec2_volumes_with_default_filters.py | How to use default filter for tags, helpfull in deleting volumes where key=value pair not matching tags. tag_ec2_vol_csv.py | Tag volumes based on csv input file, csv file format, "Volume_ID","Key","Value" The script check whether same key=value pair available in in volume tags and tages volumes. If same key is available with change in value, then the script modifies the tag. From 00fd0c7aec47d574ae1e345989ee7e6227c58824 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:06:12 +0530 Subject: [PATCH 04/18] Create del_unused_vol_region.py --- del_unused_vol_region.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 del_unused_vol_region.py diff --git a/del_unused_vol_region.py b/del_unused_vol_region.py new file mode 100644 index 0000000..edc08b7 --- /dev/null +++ b/del_unused_vol_region.py @@ -0,0 +1,24 @@ +''' +Delete available and untagged volumes from all region using python filter +Created on 02-Oct-2019 + +@author: venkatraj +''' +import boto3 +from pprint import pprint +sess=boto3.session.Session(profile_name="default") +ec2_cli=sess.client(service_name="ec2", region_name="ap-south-1") # Used for waiters and list regions +for each_region in [region['RegionName'] for region in ec2_cli.describe_regions()['Regions']]: + ec2_res=sess.resource(service_name="ec2", region_name=each_region) + ec2_cli=sess.client(service_name="ec2", region_name=each_region) + print ("Checking for "+each_region) + #Delete available and untagged volumes + for each_ec2_vol in ec2_res.volumes.all(): + if each_ec2_vol.state == 'available' and each_ec2_vol.tags == None: + ec2_res.Volume(each_ec2_vol.id).delete() + try: + waiter = ec2_cli.get_waiter('volume_deleted') + waiter.wait(VolumeIds=[each_ec2_vol.id]) + print ("\n"+ each_ec2_vol.id +" volume deleted") + except Exception as e: + print (e) From f34ebe82dc77ab02bc2c34a438f5cb16e908669e Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:17:35 +0530 Subject: [PATCH 05/18] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11e1108..0ee2cbd 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ C:\Users\venkatraj\Desktop\boto3> ### Code Code Name | Description ----------|------------- -delete_ec2_unused_vol.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags. +del_unused_vol.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags for a specific region. +del_unused_vol_region.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags for all region. inventory_ec2_vol_sg.py | Creates a inventory in the form of csv file in the current location for ec2 instances, volumes and security group for a specified region. list_ec2_volumes_with_boto3_filters.py | How to use boto3 filter for tags list_ec2_volumes_with_default_filters.py | How to use default filter for tags, helpfull in deleting volumes where key=value pair not matching tags. From 7f5c6f51daa419009bcb9155b046baea9d5e27d3 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:18:29 +0530 Subject: [PATCH 06/18] Rename delete_ec2_unused_vol.py to del_unused_vol.py --- delete_ec2_unused_vol.py => del_unused_vol.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename delete_ec2_unused_vol.py => del_unused_vol.py (100%) diff --git a/delete_ec2_unused_vol.py b/del_unused_vol.py similarity index 100% rename from delete_ec2_unused_vol.py rename to del_unused_vol.py From 69d1f6c49bacc439a7e3f5dfe66d26b49ed374ee Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:20:04 +0530 Subject: [PATCH 07/18] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ee2cbd..f6a9ad3 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ C:\Users\venkatraj\Desktop\boto3> ### Code Code Name | Description ----------|------------- -del_unused_vol.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags for a specific region. -del_unused_vol_region.py | Deletes unused volumes i.e. volume unassigned with any ec2 instance with no tags for all region. +del_unused_vol.py | Deletes unused volumes for a specific region i.e. volume unassigned with any ec2 instance with no tags. +del_unused_vol_region.py | Deletes unused volumes for all region i.e. volume unassigned with any ec2 instance with no tags. inventory_ec2_vol_sg.py | Creates a inventory in the form of csv file in the current location for ec2 instances, volumes and security group for a specified region. list_ec2_volumes_with_boto3_filters.py | How to use boto3 filter for tags list_ec2_volumes_with_default_filters.py | How to use default filter for tags, helpfull in deleting volumes where key=value pair not matching tags. From 5d93da408f1e627cbb24d808095d443d4de979d8 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:25:39 +0530 Subject: [PATCH 08/18] Create sdsd --- sss/sdsd | 1 + 1 file changed, 1 insertion(+) create mode 100644 sss/sdsd diff --git a/sss/sdsd b/sss/sdsd new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/sss/sdsd @@ -0,0 +1 @@ + From a53d3f8e396ebf4cca5e4065c59264aaa31f32bf Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:27:00 +0530 Subject: [PATCH 09/18] Rename sss/sdsd to lambda/README.md --- sss/sdsd => lambda/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sss/sdsd => lambda/README.md (100%) diff --git a/sss/sdsd b/lambda/README.md similarity index 100% rename from sss/sdsd rename to lambda/README.md From fda11aa8f21ed83c9d8dd2cf1ef6d24c5c250bd2 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:30:36 +0530 Subject: [PATCH 10/18] Update README.md --- lambda/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lambda/README.md b/lambda/README.md index 8b13789..5ab4597 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -1 +1,36 @@ +## Automation with lambda & boto3 +### Getting Started +boto3 is a python module that allows you to automat aws services, which can be used with aws lambda to create a serverless application. +### Prerequisite +1. Python 3.7.4 +2. aws-cli +>pip install awscli --user +3. boto3 +>pip install boto3 --user +### Configuring awscli credencials +Steps to configure aws credencials +C:\Users\venkatraj\Desktop\boto3>pip install awscli --user +C:\Users\venkatraj\Desktop\boto3>aws configure +AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXXXX +AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +Default region name [None]: ap-south-1 +Default output format [None]: json +C:\Users\venkatraj\Desktop\boto3> + +### Code +Code Name | Description +----------|------------- +del_unused_vol.py | Deletes unused volumes for a specific region i.e. volume unassigned with any ec2 instance with no tags. +del_unused_vol_region.py | Deletes unused volumes for all region i.e. volume unassigned with any ec2 instance with no tags. +inventory_ec2_vol_sg.py | Creates a inventory in the form of csv file in the current location for ec2 instances, volumes and security group for a specified region. +list_ec2_volumes_with_boto3_filters.py | How to use boto3 filter for tags +list_ec2_volumes_with_default_filters.py | How to use default filter for tags, helpfull in deleting volumes where key=value pair not matching tags. +tag_ec2_vol_csv.py | Tag volumes based on csv input file, csv file format, "Volume_ID","Key","Value" The script check whether same key=value pair available in in volume tags and tages volumes. If same key is available with change in value, then the script modifies the tag. + +### License +GNU General Public License v3.0 +Mail Me: sureshvenkey@gmail.com +Website: www.sureshvenkey.com + + From c577dea916571ef0532de7087a0bbc667608fbf7 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:40:08 +0530 Subject: [PATCH 11/18] Update README.md --- lambda/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lambda/README.md b/lambda/README.md index 5ab4597..c266abb 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -18,15 +18,16 @@ Default region name [None]: ap-south-1 Default output format [None]: json C:\Users\venkatraj\Desktop\boto3> -### Code +### Procedure for executing lambda + +1. Create a IAM role for lambda ( here lambda is the Trusted entitie) with two policies attached to it "AmazonEC2FullAccess" and "AmazonSNSFullAccess". Here we have given full access, you can restrict if you wish. +2. Create a lambda function by + + Code Name | Description ----------|------------- del_unused_vol.py | Deletes unused volumes for a specific region i.e. volume unassigned with any ec2 instance with no tags. -del_unused_vol_region.py | Deletes unused volumes for all region i.e. volume unassigned with any ec2 instance with no tags. -inventory_ec2_vol_sg.py | Creates a inventory in the form of csv file in the current location for ec2 instances, volumes and security group for a specified region. -list_ec2_volumes_with_boto3_filters.py | How to use boto3 filter for tags -list_ec2_volumes_with_default_filters.py | How to use default filter for tags, helpfull in deleting volumes where key=value pair not matching tags. -tag_ec2_vol_csv.py | Tag volumes based on csv input file, csv file format, "Volume_ID","Key","Value" The script check whether same key=value pair available in in volume tags and tages volumes. If same key is available with change in value, then the script modifies the tag. + ### License GNU General Public License v3.0 From 70d94ef17d7d1b32f792b2cd13b2c7a2e8b35928 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:41:06 +0530 Subject: [PATCH 12/18] Create email_ec2_status.py --- lambda/email_ec2_status.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lambda/email_ec2_status.py diff --git a/lambda/email_ec2_status.py b/lambda/email_ec2_status.py new file mode 100644 index 0000000..1a551bd --- /dev/null +++ b/lambda/email_ec2_status.py @@ -0,0 +1,21 @@ +import json +import boto3 + +def lambda_handler(event, context): + # TODO implement + + ec2_res=boto3.resource(service_name="ec2", region_name="ap-south-1") + sns_cli=boto3.client(service_name="sns", region_name="ap-south-1") + #print("Received event: " + json.dumps(event['detail']['instance-id'], indent=2)) + instance_name = event['detail']['instance-id'] + message = instance_name + " Instance is in stopped state" + print(message) + sns_cli.publish(TargetArn="arn:aws:sns:ap-south-1:703691942846:sureshvenkey", + Message=message, + Subject="Ec2 Instance State") + + + return { + 'statusCode': 200, + 'body': json.dumps('Hello from Lambda!') + } From 66be97540d1538ef6dc328c1e6379a8523f990dc Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:42:35 +0530 Subject: [PATCH 13/18] Update email_ec2_status.py --- lambda/email_ec2_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/email_ec2_status.py b/lambda/email_ec2_status.py index 1a551bd..5f35e95 100644 --- a/lambda/email_ec2_status.py +++ b/lambda/email_ec2_status.py @@ -10,7 +10,7 @@ def lambda_handler(event, context): instance_name = event['detail']['instance-id'] message = instance_name + " Instance is in stopped state" print(message) - sns_cli.publish(TargetArn="arn:aws:sns:ap-south-1:703691942846:sureshvenkey", + sns_cli.publish(TargetArn="arn:XXX:XXX:XXXXXXX:XXXXXXXXX:XXXXXXXXXXXXXXXXXXX", Message=message, Subject="Ec2 Instance State") From dc9196ca04993ec7da4da5604387d2644a7e7db9 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 14:46:53 +0530 Subject: [PATCH 14/18] Update README.md --- lambda/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/README.md b/lambda/README.md index c266abb..571299d 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -26,7 +26,7 @@ C:\Users\venkatraj\Desktop\boto3> Code Name | Description ----------|------------- -del_unused_vol.py | Deletes unused volumes for a specific region i.e. volume unassigned with any ec2 instance with no tags. +email_ec2_status.py | Sends mail alert if an instance is reached to shutdown state. ### License From a660812fd0c02d75bdd797ec3b2756b4e6f7dc8f Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 15:02:30 +0530 Subject: [PATCH 15/18] Update README.md --- lambda/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lambda/README.md b/lambda/README.md index 571299d..67e1a15 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -21,12 +21,24 @@ C:\Users\venkatraj\Desktop\boto3> ### Procedure for executing lambda 1. Create a IAM role for lambda ( here lambda is the Trusted entitie) with two policies attached to it "AmazonEC2FullAccess" and "AmazonSNSFullAccess". Here we have given full access, you can restrict if you wish. -2. Create a lambda function by +2. Create a lambda function by specifying the function name, runtime(python 3.7). +3. Mention the code in function code section. +3. Select the appropriate IAM role for your function, which we have created now. You can also increase the timeout value in basic section if required, by default it is 3 seconds. +4. Once you have done save the function. +5. From cloudwatch ceate a "Event Pattern" event source by specifying the filtering criteria, example +Service Name: EC2 +Event Type: EC2 Instance State-change Notification +Specific state(s): stopped +Any instance: Yes +6. Select the created function to crecive the events from event source by selection it from Traget. +7. We are done we are about to receive the mail if the ec2 state is stopped. + + Code Name | Description ----------|------------- -email_ec2_status.py | Sends mail alert if an instance is reached to shutdown state. +email_ec2_status.py | Sends mail alert if an instance is reached to stopped state. ### License From 61d1bf647cf512861d9ff2ef7e95b4dccb641d9a Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 15:04:32 +0530 Subject: [PATCH 16/18] Update README.md --- lambda/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambda/README.md b/lambda/README.md index 67e1a15..9fc715a 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -27,9 +27,9 @@ C:\Users\venkatraj\Desktop\boto3> 4. Once you have done save the function. 5. From cloudwatch ceate a "Event Pattern" event source by specifying the filtering criteria, example Service Name: EC2 -Event Type: EC2 Instance State-change Notification -Specific state(s): stopped -Any instance: Yes +Event Type: EC2 Instance State-change Notification +Specific state(s): stopped +Any instance: Yes 6. Select the created function to crecive the events from event source by selection it from Traget. 7. We are done we are about to receive the mail if the ec2 state is stopped. From 477f556e226a410f70b00ba624acd9080ec67636 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Tue, 8 Oct 2019 15:15:53 +0530 Subject: [PATCH 17/18] Update README.md --- lambda/README.md | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/lambda/README.md b/lambda/README.md index 9fc715a..4fa0fbc 100644 --- a/lambda/README.md +++ b/lambda/README.md @@ -1,23 +1,7 @@ ## Automation with lambda & boto3 ### Getting Started -boto3 is a python module that allows you to automat aws services, which can be used with aws lambda to create a serverless application. -### Prerequisite -1. Python 3.7.4 -2. aws-cli ->pip install awscli --user -3. boto3 ->pip install boto3 --user -### Configuring awscli credencials -Steps to configure aws credencials -C:\Users\venkatraj\Desktop\boto3>pip install awscli --user -C:\Users\venkatraj\Desktop\boto3>aws configure -AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXXXX -AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Default region name [None]: ap-south-1 -Default output format [None]: json -C:\Users\venkatraj\Desktop\boto3> - +boto3 is a python module that allows you to automat aws services, which can be used with aws lambda to create a serverless application. Here we are going to create a function to send mail alert (using sns/can also be done with ses) if the ec2 instance is stopped. sns creation is simple just by creating a topic and subscription and getting verified. ### Procedure for executing lambda 1. Create a IAM role for lambda ( here lambda is the Trusted entitie) with two policies attached to it "AmazonEC2FullAccess" and "AmazonSNSFullAccess". Here we have given full access, you can restrict if you wish. From dd724e71a092b7731f1925795683f9d7c59ec116 Mon Sep 17 00:00:00 2001 From: sureshvenkey <50266914+sureshvenkey@users.noreply.github.com> Date: Thu, 17 Mar 2022 17:29:22 +0530 Subject: [PATCH 18/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6a9ad3..3b47b9b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,6 @@ tag_ec2_vol_csv.py | Tag volumes based on csv input file, csv file format, "Volu ### License GNU General Public License v3.0 Mail Me: sureshvenkey@gmail.com -Website: www.sureshvenkey.com +Website: www.venkatraj.in