This is the Python version of ebs-snapshot. This function can be deployed to AWS Lambda.
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no charge when your code is not running. With Lambda, you can run code for virtually any type of application or backend service - all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app
With AWS Lambda, you pay only for what you use. You are charged based on the number of requests for your functions and the time your code executes. The Lambda free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.
- First 1 million requests per month are free
- $0.20 per 1 million requests thereafter ($0.0000002 per request)
https://aws.amazon.com/lambda/faqs/
IAM Role Policy for AWS Lambda
-
AWS Management Console > Identity and Access Management
-
Role > Create New Role
-
Give your role a name
-
Select AWS Lambda in AWS Service Roles
-
Just skip Attach Policy by click Next Step
-
Find your new role then click on it
-
Permissions > Inline Policies > Create a new one
-
Custom Policy > Select
-
Give your policy a name
-
Copy the policy below and paste it there
{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt0123456789012", "Effect": "Allow", "Action": [ "ec2:CreateSnapshot", "ec2:CreateTags", "ec2:DeleteSnapshot", "ec2:DescribeSnapshots", "ec2:DescribeVolumes", "ses:SendRawEmail" ], "Resource": [ "*" ] } ] }
-
Validate Policy > Apply Policy
-
Clone or download the code as zip
-
Change directory to
ebs-snapshot-python
-
Open and edit
user_vars.py
# Modify me domain = 'domain.com' ret_period = 7 # day(s) mail_from = 'AWS Notification <aws@{}>'.format(domain) mail_to = ['jpdoria@{}'.format(domain)] # single recipient # mail_to = ['admin@company.com', 'user@company.com'] # multiple recipients
-
Then save and exit from the editor
-
Compress
ebs-snapshot.py
anduser-vars.py
into one zip file (ebs-snashot.zip) -
AWS Management Console > Lambda
-
Create a Lambda function > Blank function
-
Skip Configure triggers by clicking Next button
-
Give your function a name and description
-
Choose Python 2.7 as Runtime
-
Code entry type: Upload a .ZIP file, then click Upload
-
Upload the ebs-snapshot.zip you created in Step 13
-
Handler: ebs-snapshot.main
-
Role: Choose an existing role, then find the role you created in IAM Setup section
-
Memory: 128 MB and Timeout: 5 mins
-
Click Next > Create function
- AWS Management Console > CloudWatch
- Events > Rules > Create a new rule
- Event selector: Schedule, fixed rate of 1 Day
- Target: Lambda function, then select your ebs-snapshot function
- Click Configure details
- Give your a name and description
- State should be Enabled
- Click Create rule button
This project is still young and there are things that need to be done. If you have ideas that would improve this app, feel free to contribute!
MIT License
Copyright (c) 2017 John Paul P. Doria
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.