hooglcolumbus.blogg.se

Mymind unsplash
Mymind unsplash












mymind unsplash
  1. #MYMIND UNSPLASH UPDATE#
  2. #MYMIND UNSPLASH CODE#

This was set by us in the serverless.yml file shown above.

#MYMIND UNSPLASH CODE#

The method ‘asg_ec2_age_check()’ is where Amazon hands over control to our code for execution.Let us take a look at our code in handler.py The function will remain in your account, but not run on it’s own. If you at any time want to disable the schedule, you can just set enabled: false and do a sls deploy.Set a schedule that will work for your application. Again this is for demonstration purpose only. The default timeout for Lambda function should be enough, but I wanted to show where it is set, so I used 10s as the value.I have specified that the maximum memory to be allocated for the function should be 128 MB.

mymind unsplash

The name of the function will be a combination of the service name, stage and function name.This is followed by the function section, where we define the entry point of our Lambda function.When the Lambda functions runs, the role created for it will have these permissions. Next is the IAM role and its permissions.A bucket that is used by the serverless framework for storing the code.The runtime specifies the function will use Python 3.7.In the provider section, we specify that this file is for AWS environment.

mymind unsplash

Let us take a look at the serverless.yml file. The file serverless.yml contains information about our Lambda function and the IAM role that will be needed by the function.įile handler.py is where we will write the code which accomplishes our task.

#MYMIND UNSPLASH UPDATE#

Here you will see two files serverless.yml and handler.py, I are going to update these files with our code as shown below. sls create -template aws-python3 -path asg-ec2-age-check To create the template for our work, I run the commands as shown below. The age check can be changed in handler.py, so that you dont have to run EC2 instances for a long time to test out the function. You need at least one AWS Auto Scaling Group with some servers in it for testing. The workstation should have a ‘IAM Role’ or ‘Access Keys’ configured correctly. Make sure you have installed the Serverless Framework on your workstation.Įnsure that the workstation from where you are going to run the serverless framework has all the necessary permissions to publish your Lambda function. Always test code in a non production environment before publishing to production. Please make sure you test this in an account where you are certain removal of EC2 instances will not impact your workload. However, for this post, I am going to go the serverless route and demonstrate how this could be achieved.įor demonstration purpose, I choose a time of one day, but in reality you should consider what is more appropriate for your account and application. The second method is to run it as a lambda function triggered by CloudWatch Events rule.Įither way works and people can argue merits of one over the other. There are two ways that came to my mind, one was to write a python script and run it on schedule from my Jenkins server as it had a lot of spare capacity. I do not have access to the source code or know the method implemented to do this, so I decided to write a lambda function on my own and see how I could accomplish this task. One of the security mandate is that all EC2 instances in any auto scaling group be terminated after a certain period of time.Īs far as I know, a lambda function is used to terminate EC2 instances during off peak hours for the application.

mymind unsplash

The firm where I am working right now has a strong emphasis on security for infrastructure in the public cloud.














Mymind unsplash