Lambda recently started learning from scratch using automation in AWS inside. My operation is based mainly on the version of Python 3.7, AWS Python module, called Boto. The syntax and concepts do not go into specific examples of direct view.
First, let's first look at a simple operation, how to create a new EC2 instance.
First, create a new lambda function, select the author from scratch, where he will automatically create a default role of an IAM, and give access to cloudwatch log in
The default permissions are shown below
Here we need to grant permission to create EC2, so the need to modify the corresponding JSON. We can find this Role created by default in the IAM's role which, added to the default permissions ec2 above: runinstances access it. Of course, we can start to create a new role on manually.
The following is a chart of authority after update
Next is the Lambda function. Lambda functions are triggered by events, so there are parameters passed event and context.
Which is introduced into the first function module
next incoming several environment variables, these environment variables are defined in the function directly from the following table which
is then lambda_handler function inside the entrance, to create a new instance of EC2 directly imported parameters . Note that this function has two formal parameters event and context, this is a function built-in, where we do not have access, but still need to write on
These environment variables representing the AMI code, instance type, Key pair name and subnet subnet Code
Click test, will remind event configuration test, where we do not need to pass any arguments, so choose the simplest hello world template, passing a null parameter on the line
Click Save after test again, it will show the successful implementation
Look EC2 instances, indeed a new instance has been created!