linux_wiki:lambda_python_function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:lambda_python_function [2019/08/09 22:13]
billdozor [Lambda: Pre-Reqs]
linux_wiki:lambda_python_function [2019/08/09 22:29]
billdozor [File Conversion Example: Configure]
Line 55: Line 55:
  
 ---- ----
 +
 +===== Stop/Start EC2 Example: Pre-Reqs =====
 +
 +Create an IAM role
 +  * Services > Security > IAM > Roles > Create Role
 +    * Choose a service that will use the role: Lambda
 +    * Click 'Next:Permissions'
 +    * **Required**: Attach the AWS managed policy "AWSLambdaBasicExecutionRole" to your new role in order to log your Lambda function to cloudwatch logs.
 +    * Also, Create a new policy to allow basic EC2 list,stop,start. Example:<code json>{
 +    "Version": "2012-10-17",
 +    "Statement": [
 +        {
 +            "Sid": "VisualEditor0",
 +            "Effect": "Allow",
 +            "Action": [
 +                "ec2:DescribeInstances",
 +                "ec2:StartInstances",
 +                "ec2:StopInstances"
 +            ],
 +            "Resource": "*"
 +        }
 +    ]
 +}</code>
 +
 +----
 +
  
 ====== Lambda: Create Function ====== ====== Lambda: Create Function ======
Line 95: Line 121:
  
 ---- ----
 +
 +===== Stop/Start EC2 Example: Configure =====
 +
 +  * Click 'Add trigger'
 +    * Select CloudWatch Events from the dropdown
 +    * Rule: Create a new rule
 +    * Rule name: <any name>
 +    * Description: <any description>
 +    * Rule type: Select 'Schedule expression'
 +    * Schedule expression: 00 05 * * ? *
 +      * Expressions are in UTC: Example is every day at midnight (CDT)
 +      * Minute Hour DayOfMonth Month DayOfWeek Year
 +        * [[https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html|More info here]]
 +    * Ensure 'Enable trigger' is checked
 +    * Click "Add"
 +  * Select the Lambda function in the middle of the designer
 +    * The function can now be edited inline or you can package up a Python function and upload it.
 +      * Edit code inline: Use when the function is simple and does not require any dependencies that you would need a package installed for.
 +      * Upload a zip file: When you develop the function outside of the AWS console and/or need dependencies installed.
 +
 +----
 +
  
 ====== Lambda: Package and Upload Function ====== ====== Lambda: Package and Upload Function ======
  • linux_wiki/lambda_python_function.txt
  • Last modified: 2019/08/09 22:29
  • by billdozor