{"id":1941,"date":"2022-11-09T10:06:41","date_gmt":"2022-11-09T10:06:41","guid":{"rendered":"https:\/\/www.easydeploy.io\/blog\/?p=1941"},"modified":"2023-03-03T11:44:03","modified_gmt":"2023-03-03T11:44:03","slug":"lambda-automation-for-ami-creation-with-terraform","status":"publish","type":"post","link":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/","title":{"rendered":"Lambda Automation for AMI Creation with Terraform"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">\u00a0<strong><em>Amazon Machine Image <\/em><\/strong>is known as <em><\/em><strong><em>AMI<\/em><\/strong>\u00a0that makes it easier and faster to recover an instance in case of disaster or failure of an instance. So, here we are going to create custom <strong>AMIs<\/strong> from any instances that have some particular tags in an automation way using Lambda.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong style=\"font-weight: 400;\">Lambda<\/strong> is an <strong style=\"font-weight: 400;\">event<\/strong>&#8211;<strong style=\"font-weight: 400;\">driven<\/strong>, <b>server less<\/b>\u00a0computing platform provided by AWS. It simplifies the process of building smaller, on-demand applications that are responsive to events and new information. It runs code in response to events and automatically manages instances or any other services based on the code.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now we are going to create some of the resources that we need to automate this process using <strong>Terraform<\/strong>. So, Let\u2019s dive into this.<\/span><\/p>\n<h2>Create an IAM Role and Policy<\/h2>\n<p><span style=\"font-weight: 400;\">First we have to create an <strong>IAM Policy<\/strong> that has some permissions to access our instances.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So create a file called<strong> provider.tf<\/strong> and add the following code in it.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">provider<\/span> <span style=\"font-weight: 400;\">\"aws\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">region\u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"us-east-1\"<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Then create another file named as<strong> iam.tf<\/strong> file. This is the one that has the policy and role.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Add the below code in <strong>iam.tf<\/strong> file.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_iam_policy\"<\/span> <span style=\"font-weight: 400;\">\"policy\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"AMIAutomationLamdaPolicy\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">path\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"\/\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">description <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"My test policy\"<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">policy <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">jsonencode<\/span><span style=\"font-weight: 400;\">(<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Version\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"2012-10-17\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Statement\"<\/span><span style=\"font-weight: 400;\"> : [<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Effect\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"Allow\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Action\"<\/span><span style=\"font-weight: 400;\"> : [<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"logs:CreateLogGroup\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"logs:CreateLogStream\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"logs:PutLogEvents\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0],<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Resource\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"arn:aws:logs:*:*:*\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Effect\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"Allow\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Action\"<\/span><span style=\"font-weight: 400;\"> : [<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:CreateImage\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:CreateTags\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:DeleteSnapshot\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:DeregisterImage\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:DescribeImages\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"ec2:DescribeInstances\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0],<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Resource\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"*\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0]<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0)<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_iam_role\"<\/span> <span style=\"font-weight: 400;\">\"role\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"AMIAutomationLamdaRole\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">assume_role_policy <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">jsonencode<\/span><span style=\"font-weight: 400;\">(<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Version\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"2012-10-17\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Statement\"<\/span><span style=\"font-weight: 400;\"> : [<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Effect\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"Allow\"<\/span><span style=\"font-weight: 400;\">,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Principal\"<\/span><span style=\"font-weight: 400;\"> : {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Service\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"lambda.amazonaws.com\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\"Action\"<\/span><span style=\"font-weight: 400;\"> : <\/span><span style=\"font-weight: 400;\">\"sts:AssumeRole\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0]<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0})<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">managed_policy_arns <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">aws_iam_policy<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">policy<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">arn<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li><span style=\"font-weight: 400;\">This code will create an <strong>IAM Policy<\/strong> named as <strong>AMIAutomationLamdaPolicy<\/strong> and an <strong>IAM Role<\/strong> named <strong>AMIAutomationLamdaRole.<\/strong>\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">So now run <em><strong>terraform init<\/strong><\/em> command to initialize the dependencies for our code.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Then run <em><strong>terraform plan<\/strong><\/em> and <em><strong>apply<\/strong><\/em> commands to deploy your code to aws.<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/1.png\" alt=\"Terraform-Lambda-Automation-Iam-apply\" class=\"aligncenter wp-image-1963 \" title=\"Terraform-Lambda-Automation-Iam-apply\" width=\"644\" height=\"193\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/1.png 1041w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/1-300x90.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/1-1024x307.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/1-768x230.png 768w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Once creation is completed successfully, you can go to your aws account and navigate to <strong>IAM<\/strong> and you can see the <strong>role<\/strong> and <strong>policy<\/strong> will be created.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/2.png\" alt=\"Terraform-Lambda-Automation-Iam-Policy\" class=\"aligncenter wp-image-1964 \" title=\"Terraform-Lambda-Automation-Iam-Policy\" width=\"819\" height=\"185\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/2.png 1422w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/2-300x68.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/2-1024x231.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/2-768x173.png 768w\" sizes=\"(max-width: 819px) 100vw, 819px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/3.png\" alt=\"Terraform-Lambda-Automation-Iam-Role\" class=\"aligncenter wp-image-1965 \" title=\"Terraform-Lambda-Automation-Iam-Role\" width=\"788\" height=\"222\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/3.png 1441w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/3-300x84.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/3-1024x288.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/3-768x216.png 768w\" sizes=\"(max-width: 788px) 100vw, 788px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">And click on the <strong>IAM Role<\/strong> it shows the list of policies that are assigned with this role.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/4.png\" alt=\"Terraform-Lambda-Automation-Iam-Role-Policy\" class=\"aligncenter wp-image-1966 \" title=\"Terraform-Lambda-Automation-Iam-Role-Policy\" width=\"795\" height=\"415\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/4.png 1440w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/4-300x156.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/4-1024x534.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/4-768x401.png 768w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Here we just create one custom policy and that will be assigned with our created role.<\/span><\/p>\n<h2>Create EC2 Instance<\/h2>\n<p><span style=\"font-weight: 400;\">Now we need to create an <strong>EC2 instance<\/strong> which is the source for our custom <strong>AMI.<\/strong>\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Create a new file <strong>instance.tf<\/strong> and copy the below code and paste it.<\/span><\/p>\n<div>\n<div>\n<div>\n<pre><span>resource<\/span><span> <\/span><span>\"aws_instance\"<\/span><span> <\/span><span>\"test\"<\/span><span> {<\/span>\r\n<span>  <\/span><span>ami<\/span><span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0      <\/span><span>=<\/span><span> <\/span><span>\"ami-0ff8a91507f77f867\"<\/span>\r\n<span>  <\/span><span>instance_type<\/span><span> <\/span><span>=<\/span><span> <\/span><span>\"t2.micro\"<\/span>\r\n<span>  <\/span><span>tags<\/span><span> <\/span><span>=<\/span><span> <\/span><span>{<\/span>\r\n<span>  \u00a0 <\/span><span>Name<\/span><span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0            = <\/span><span>\"lambda-automation\"<\/span>\r\n<span>  \u00a0 <\/span><span>AutoDigiBackupRetentionDays<\/span><span> = <\/span><span>7<\/span>\r\n<span>  \u00a0 A<\/span><span>utoDigiBackup<\/span><span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0        = <\/span><span>\"yes\"<\/span>\r\n<span>  \u00a0 <\/span><span>AutoDigiBackupSchedule<\/span><span> \u00a0 \u00a0 \u00a0   = <\/span><span>\"*\"<\/span>\r\n<span>  \u00a0 <\/span><span>AutoDigiNoReboot<\/span><span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0      = <\/span><span>true<\/span>\r\n<span>  }<\/span>\r\n<span>}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><span style=\"font-weight: 400;\">Our code will create an instance with some tags. Because these tags are helped to identify by <strong>Lambda<\/strong> function to which instances are needed to create <strong>AMIs.<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0So now run <strong><em>terraform apply<\/em><\/strong> command to create an instance.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/5.png\" alt=\"Terraform-Lambda-Automation-ec2-apply\" class=\"aligncenter wp-image-1967 \" title=\"Terraform-Lambda-Automation-ec2-apply\" width=\"481\" height=\"248\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/5.png 665w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/5-300x155.png 300w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Once it completes go to aws account and <strong>Ec2<\/strong> page, you can see the <strong>Instance<\/strong> will be created.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6.png\" alt=\"Terraform-Lambda-Automation-EC2\" class=\"aligncenter wp-image-1968 size-full\" title=\"Terraform-Lambda-Automation-EC2\" width=\"1575\" height=\"197\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6.png 1575w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6-300x38.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6-1024x128.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6-768x96.png 768w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/6-1536x192.png 1536w\" sizes=\"(max-width: 1575px) 100vw, 1575px\" \/><\/p>\n<h2>Create Lambda Functions and Triggers with EventRules<\/h2>\n<ul>\n<li><span style=\"font-weight: 400;\">We have to create <strong>2\u00a0Lambda<\/strong> functions, one for <strong>creating AMIs<\/strong> and another one for <strong>deleting AMIs.<\/strong><\/span><\/li>\n<li><span style=\"font-weight: 400;\">Because the AMIs will expire at a particular time.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click this <a href=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/createami.zip\">createami<\/a>.zip to download the code for <strong>AMICreationLambda<\/strong> function and Click this <a href=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/deleteami.zip\">deleteami<\/a>.zip to download the code for <strong>AMIDeletionLambda<\/strong> function.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Add these two zip files to the folder where you have your <strong>Terraform<\/strong> code.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Now create a <strong>lambda.tf<\/strong> file and copy and paste the below code into that file.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_lambda_function\"<\/span> <span style=\"font-weight: 400;\">\"lambda\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">count\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0        <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">2<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">filename \u00a0 \u00a0 \u00a0         <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> var<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">lambda_file<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">function_name\u00a0     <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> var<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">function_name<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">role \u00a0 \u00a0 \u00a0 \u00a0 \u00a0          \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> aws_iam_role<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">role<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">arn<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">handler\u00a0 \u00a0 \u00a0        \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"<\/span><span style=\"font-weight: 400;\">${<\/span><span style=\"font-weight: 400;\">local<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">handler<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span><span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\">.handler\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">source_code_hash <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">filebase64sha256<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">\"<\/span><span style=\"font-weight: 400;\">${<\/span><span style=\"font-weight: 400;\">var<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">lambda_file<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span><span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\">\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">timeout\u00a0 \u00a0 \u00a0 \u00a0 \u00a0       <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">180<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">runtime\u00a0 \u00a0 \u00a0 \u00a0 \u00a0       <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"nodejs16.x\"<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">locals<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">handler                 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">\"createami\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"deleteami\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">This code will create 2 <strong>Lambda functions<\/strong> and it uses the <strong>Role<\/strong> which we created at the beginning of this article.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Create another file named <\/span><b>variable.tf<\/b><span style=\"font-weight: 400;\"> and paste the below code to that file.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">variable<\/span> <span style=\"font-weight: 400;\">\"lambda_file\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">description <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"List of Name for the two lambda code files \"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">type\u00a0 \u00a0 \u00a0 \u00a0   <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">list<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">string<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">default \u00a0 \u00a0  <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">\"createami.zip\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"deleteami.zip\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">variable<\/span> <span style=\"font-weight: 400;\">\"function_name\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">description  <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"List of Name for the event rules\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">type\u00a0 \u00a0 \u00a0 \u00a0    <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">list<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">string<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">default \u00a0 \u00a0   <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">\"AMICreationLambda\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"AMIDeletionLambda\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li><span style=\"font-weight: 400;\">These variables give values to the <strong>Lambda<\/strong> code. It gives 2 function names and 2 file names.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In our <strong>Lambda function<\/strong> we use the latest runtime <strong>node 16x<\/strong>.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Copy the below code and paste into the <strong>lambda.tf<\/strong> file.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_cloudwatch_event_rule\"<\/span> <span style=\"font-weight: 400;\">\"lambda\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">count \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0         <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">2<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">name\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0        <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> var<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">event_name<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">schedule_expression <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> var<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">crontab<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_cloudwatch_event_target\"<\/span> <span style=\"font-weight: 400;\">\"lambda\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">count <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">2<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">rule\u00a0  <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">aws_cloudwatch_event_rule.<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">].<\/span><span style=\"font-weight: 400;\">id<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">arn \u00a0  <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">aws_lambda_function.<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">].<\/span><span style=\"font-weight: 400;\">arn<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">resource<\/span> <span style=\"font-weight: 400;\">\"aws_lambda_permission\"<\/span> <span style=\"font-weight: 400;\">\"allow_event\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">count \u00a0 \u00a0 \u00a0      \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">2<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">action\u00a0 \u00a0 \u00a0        <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"lambda:InvokeFunction\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">function_name <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">aws_lambda_function.<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">].<\/span><span style=\"font-weight: 400;\">function_name<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">principal \u00a0 \u00a0      <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"events.amazonaws.com\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">source_arn\u00a0 \u00a0   <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">aws_cloudwatch_event_rule.<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">count<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">index<\/span><span style=\"font-weight: 400;\">].<\/span><span style=\"font-weight: 400;\">arn<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">What this code will do is it will create <strong>2 EventRules<\/strong> for Invoke the <strong>Lambda<\/strong> functions in a particular time regularly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Copy this code and paste into <strong>variable.tf<\/strong> file.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">variable<\/span> <span style=\"font-weight: 400;\">\"event_name\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">description <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"List of Name for the event rules\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">type\u00a0 \u00a0 \u00a0   \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">list<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">string<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">default \u00a0   \u00a0 <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">\"AMICreationRule\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"AMIDeletionRule\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">variable<\/span> <span style=\"font-weight: 400;\">\"crontab\"<\/span><span style=\"font-weight: 400;\"> {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">description <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">\"List of crontab schedule for the event rules\"<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">type\u00a0 \u00a0 \u00a0     <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">list<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">any<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0<\/span><span style=\"font-weight: 400;\">default \u00a0 \u00a0  <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">[<\/span><span style=\"font-weight: 400;\">\"cron(0 07 * * ? *)\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"cron(0 02 * * ? *)\"<\/span><span style=\"font-weight: 400;\">] <\/span><span style=\"font-weight: 400;\">#cron(0 02 * * ? *)\u00a0 # IST 07:30am<\/span>\r\n<span style=\"font-weight: 400;\">}\r\n\r\n<\/span><\/pre>\n<ul>\n<li><span style=\"font-weight: 400;\">To trigger the Lambda function on a regular basis, we have to set a time as a <strong>crontab<\/strong> in <strong>EventRule.<\/strong>\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">As I mentioned in the above code, <strong>crontab<\/strong> is uses type <strong>UTC.<\/strong> So we have converted our <strong>IST<\/strong> time to <strong>UTC.<\/strong> You can set for everyday morning at 7.30 am to <strong>crontab<\/strong> is <em><strong>crontab(0 02 * * ? *)<\/strong><\/em>.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">For the first one I use my current time when I write this article, to demonstrate you. You can set the time to an extra 10 minutes from now. Then only you can check whether the Lambda function will create <strong>AMI<\/strong> or not.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Now run terraform to create <strong>Lambda Functions<\/strong> and <strong>Event Rules.<\/strong><\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/7.png\" alt=\"Terraform-Lambda-Automation-lambda-apply\" class=\"aligncenter wp-image-1969 \" title=\"Terraform-Lambda-Automation-lambda-apply\" width=\"815\" height=\"398\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/7.png 1132w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/7-300x147.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/7-1024x500.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/7-768x375.png 768w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Once completed go to your aws account and Lambda page to see your <strong>Lambda Functions.<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/8.png\" alt=\"Terraform-Lambda-Automation-Functions\" class=\"aligncenter wp-image-1970 \" title=\"Terraform-Lambda-Automation-Functions\" width=\"850\" height=\"222\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/8.png 1445w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/8-300x78.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/8-1024x267.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/8-768x200.png 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Now go to the <strong>EventBridge<\/strong> section and click <strong>EventRule<\/strong> on the left navigation, you are able to see the event rules that your terraform script creates.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/9.png\" alt=\"Terraform-Lambda-Automation-EventRules\" class=\"aligncenter wp-image-1971 \" title=\"Terraform-Lambda-Automation-EventRules\" width=\"895\" height=\"213\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/9.png 1482w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/9-300x71.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/9-1024x244.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/9-768x183.png 768w\" sizes=\"(max-width: 895px) 100vw, 895px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click the <strong>AMICreationRule Event Rule<\/strong> to see the details of the rule.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/10.png\" alt=\"Terraform-Lambda-Automation-crontab\" class=\"aligncenter wp-image-1972 \" title=\"Terraform-Lambda-Automation-crontab\" width=\"497\" height=\"395\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/10.png 806w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/10-300x238.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/10-768x610.png 768w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Here you can see the next 10 trigger dates in your local time zone. So wait for it to trigger the <strong>Lambda function.<\/strong><\/span><\/p>\n<h2>Lambda Functions Creates AMI<\/h2>\n<p><span style=\"font-weight: 400;\">Once the time comes that you have scheduled the <strong>EventRule<\/strong> to trigger your <strong>Lambda<\/strong> function, go to your AWS account and navigate to the <strong>CloudWatch group<\/strong> section.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/11.png\" alt=\"Terraform-Lambda-Automation-log-group\" class=\"aligncenter wp-image-1973 size-full\" title=\"Terraform-Lambda-Automation-log-group\" width=\"1502\" height=\"338\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/11.png 1502w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/11-300x68.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/11-1024x230.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/11-768x173.png 768w\" sizes=\"(max-width: 1502px) 100vw, 1502px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">You are able to see a <strong>log group<\/strong> which is created by your lambda Function. Click the<strong> log group.<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/12.png\" alt=\"Terraform-Lambda-Automation-log-streams\" class=\"aligncenter wp-image-1974 size-full\" title=\"Terraform-Lambda-Automation-log-streams\" width=\"1497\" height=\"332\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/12.png 1497w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/12-300x67.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/12-1024x227.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/12-768x170.png 768w\" sizes=\"(max-width: 1497px) 100vw, 1497px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In the <strong>Log streams<\/strong> section there will be a <strong>log stream<\/strong>. Click it to see the logs that come from Lambda.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/13.png\" alt=\"Terraform-Lambda-Automation-log-events\" class=\"aligncenter wp-image-1975 size-full\" title=\"Terraform-Lambda-Automation-log-events\" width=\"1511\" height=\"802\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/13.png 1511w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/13-300x159.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/13-1024x544.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/13-768x408.png 768w\" sizes=\"(max-width: 1511px) 100vw, 1511px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">You can see the log details. It says, find the instance which has some tags and create an <strong>AMI<\/strong> named <strong>lambda-automation_DATETODEL<\/strong> from that instance and add a tag <strong>NoReboot: true<\/strong> to that <strong>AMI.<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">So now go to the <strong>EC2<\/strong> section and choose <strong>AMIs,<\/strong> there will be an <strong>AMI<\/strong> which is created by your Lambda Function.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14.png\" alt=\"Terraform-Lambda-Automation-EC2-AMI\" class=\"aligncenter wp-image-1976 size-full\" title=\"Terraform-Lambda-Automation-EC2-AMI\" width=\"1580\" height=\"217\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14.png 1580w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14-300x41.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14-1024x141.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14-768x105.png 768w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/14-1536x211.png 1536w\" sizes=\"(max-width: 1580px) 100vw, 1580px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click the <strong>AMI<\/strong> named <strong>lambda-automation_DATETODEL<\/strong> and choose Tags you can see the tag <strong>NoReboot: true<\/strong>.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/15.png\" alt=\"Terraform-Lambda-Automation-EC2-Tags\" class=\"aligncenter wp-image-1977 \" title=\"Terraform-Lambda-Automation-EC2-Tags\" width=\"343\" height=\"149\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/15.png 463w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/15-300x130.png 300w\" sizes=\"(max-width: 343px) 100vw, 343px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">This is the tag helps to identify the <strong>AMI<\/strong> by the <strong>AMIDeletionLambda<\/strong> Function to delete the <strong>AMI<\/strong> once it expires.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Go to the Lambda section and select the <strong>AMIDeletionLambda<\/strong> function.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16.png\" alt=\"Terraform-Lambda-Automation-function-Test\" class=\"aligncenter wp-image-1978 size-full\" title=\"Terraform-Lambda-Automation-function-Test\" width=\"1707\" height=\"702\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16.png 1707w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16-300x123.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16-1024x421.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16-768x316.png 768w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/16-1536x632.png 1536w\" sizes=\"(max-width: 1707px) 100vw, 1707px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click the <strong>Test<\/strong> section and then click the <strong>Test<\/strong> button to execute the Lambda.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once it completes its execution, navigate to the <strong>CloudWatch Log<\/strong> group section.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/17.png\" alt=\"Terraform-Lambda-Automation-log-group-2\" class=\"aligncenter wp-image-1979 size-full\" title=\"Terraform-Lambda-Automation-log-group-2\" width=\"1527\" height=\"358\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/17.png 1527w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/17-300x70.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/17-1024x240.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/17-768x180.png 768w\" sizes=\"(max-width: 1527px) 100vw, 1527px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">When this <strong>AMIDeletionLambda<\/strong> function triggers, it creates a new <strong>log group<\/strong> as shown in the above screenshot. Select the <strong>Log group<\/strong> and you can see the <strong>log streams<\/strong> like the below picture.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/18.png\" alt=\"Terraform-Lambda-Automation-log-streams-2\" class=\"aligncenter wp-image-1980 size-full\" title=\"Terraform-Lambda-Automation-log-streams-2\" width=\"1493\" height=\"346\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/18.png 1493w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/18-300x70.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/18-1024x237.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/18-768x178.png 768w\" sizes=\"(max-width: 1493px) 100vw, 1493px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Click the <strong>log stream<\/strong> and get into it. You can see the logs that show <strong>Not yet time to delete<\/strong>. It means Our newly created <strong>AMI<\/strong> has not expired. So, <strong>This lambda function could not delete the AMI.<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/19.png\" alt=\"Terraform-Lambda-Automation-log-events-2\" class=\"aligncenter wp-image-1981 size-full\" title=\"Terraform-Lambda-Automation-log-events-2\" width=\"1500\" height=\"696\" srcset=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/19.png 1500w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/19-300x139.png 300w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/19-1024x475.png 1024w, https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/09\/19-768x356.png 768w\" sizes=\"(max-width: 1500px) 100vw, 1500px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">That\u2019s all I want to show you about the Lambda automation process. In this process our lambda uses <strong>node js code<\/strong> for <strong>creating<\/strong> and <strong>deleting<\/strong> the <strong>AMIs.<\/strong> We successfully created this automation process using a simple terraform script. <\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Amazon Machine Image is known as AMI\u00a0that makes it easier and faster to recover an instance in case of disaster or failure of an instance. So, here we are going to create custom AMIs from any instances that have some particular tags in an automation way using Lambda. Lambda is an event&#8211;driven, server less\u00a0computing platform [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":2410,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[424],"tags":[432],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Lambda Automation of AMI Creation using Terraform<\/title>\n<meta name=\"description\" content=\"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lambda Automation of AMI Creation using Terraform\" \/>\n<meta property=\"og:description\" content=\"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\" \/>\n<meta property=\"og:site_name\" content=\"easydeploy.io\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/Jerinrathnam\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-09T10:06:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-03T11:44:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Jerin Rathnam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jerin_rathnam\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jerin Rathnam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\"},\"author\":{\"name\":\"Jerin Rathnam\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/939543ac3b33fadea8b5115ab9a1280f\"},\"headline\":\"Lambda Automation for AMI Creation with Terraform\",\"datePublished\":\"2022-11-09T10:06:41+00:00\",\"dateModified\":\"2023-03-03T11:44:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\"},\"wordCount\":1056,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp\",\"keywords\":[\"lambda automation\"],\"articleSection\":[\"Terraform\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\",\"url\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\",\"name\":\"Lambda Automation of AMI Creation using Terraform\",\"isPartOf\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp\",\"datePublished\":\"2022-11-09T10:06:41+00:00\",\"dateModified\":\"2023-03-03T11:44:03+00:00\",\"description\":\"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage\",\"url\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp\",\"contentUrl\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp\",\"width\":1280,\"height\":720,\"caption\":\"lambda automation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.easydeploy.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lambda Automation for AMI Creation with Terraform\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#website\",\"url\":\"https:\/\/www.easydeploy.io\/blog\/\",\"name\":\"easydeploy.io\",\"description\":\"A Cloud Architect Company\",\"publisher\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.easydeploy.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#organization\",\"name\":\"EasyDeploy Technologies Pvt Ltd\",\"url\":\"https:\/\/www.easydeploy.io\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2019\/02\/easydeploy.png\",\"contentUrl\":\"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2019\/02\/easydeploy.png\",\"width\":536,\"height\":100,\"caption\":\"EasyDeploy Technologies Pvt Ltd\"},\"image\":{\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/939543ac3b33fadea8b5115ab9a1280f\",\"name\":\"Jerin Rathnam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ca2c2ab4a28d380073334816b42aaa40?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ca2c2ab4a28d380073334816b42aaa40?s=96&d=mm&r=g\",\"caption\":\"Jerin Rathnam\"},\"description\":\"Jerin Rathnam is a proficient DevOps engineer who is dedicated to streamlining software development and deployment processes. He has extensive knowledge of cloud infrastructure, containerization, and CI\/CD pipelines, which enables him to effectively connect development and operations. Jerin specializes in creating numerous Terraform modules for multi-cloud infrastructure and possesses immense expertise in configuring and managing cloud infrastructure. His profound understanding of containerization, along with his experience in orchestration tools like Docker and Kubernetes, further supports his skills as a valuable DevOps engineer.\",\"sameAs\":[\"https:\/\/www.gemjerin.site\",\"https:\/\/www.facebook.com\/Jerinrathnam\",\"https:\/\/www.instagram.com\/gem_jerin_rathnam\/\",\"https:\/\/www.linkedin.com\/in\/jerin-rathnam\/\",\"https:\/\/x.com\/jerin_rathnam\",\"@jerinrathnam\"],\"url\":\"https:\/\/www.easydeploy.io\/blog\/author\/jerin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lambda Automation of AMI Creation using Terraform","description":"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/","og_locale":"en_GB","og_type":"article","og_title":"Lambda Automation of AMI Creation using Terraform","og_description":"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!","og_url":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/","og_site_name":"easydeploy.io","article_author":"https:\/\/www.facebook.com\/Jerinrathnam","article_published_time":"2022-11-09T10:06:41+00:00","article_modified_time":"2023-03-03T11:44:03+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp","type":"image\/webp"}],"author":"Jerin Rathnam","twitter_card":"summary_large_image","twitter_creator":"@jerin_rathnam","twitter_misc":{"Written by":"Jerin Rathnam","Estimated reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#article","isPartOf":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/"},"author":{"name":"Jerin Rathnam","@id":"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/939543ac3b33fadea8b5115ab9a1280f"},"headline":"Lambda Automation for AMI Creation with Terraform","datePublished":"2022-11-09T10:06:41+00:00","dateModified":"2023-03-03T11:44:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/"},"wordCount":1056,"commentCount":0,"publisher":{"@id":"https:\/\/www.easydeploy.io\/blog\/#organization"},"image":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage"},"thumbnailUrl":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp","keywords":["lambda automation"],"articleSection":["Terraform"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/","url":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/","name":"Lambda Automation of AMI Creation using Terraform","isPartOf":{"@id":"https:\/\/www.easydeploy.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage"},"image":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage"},"thumbnailUrl":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp","datePublished":"2022-11-09T10:06:41+00:00","dateModified":"2023-03-03T11:44:03+00:00","description":"Learn how to automate Lambda for creation with Amazon Machine Image (AMI) in a step-by-step process. Learn Now!","breadcrumb":{"@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#primaryimage","url":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp","contentUrl":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2022\/11\/Easydeploy-LAMBDA-AUTOMATION-FOR-AMI-CREATION-WITH-TERRAFORM.webp","width":1280,"height":720,"caption":"lambda automation"},{"@type":"BreadcrumbList","@id":"https:\/\/www.easydeploy.io\/blog\/lambda-automation-for-ami-creation-with-terraform\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.easydeploy.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Lambda Automation for AMI Creation with Terraform"}]},{"@type":"WebSite","@id":"https:\/\/www.easydeploy.io\/blog\/#website","url":"https:\/\/www.easydeploy.io\/blog\/","name":"easydeploy.io","description":"A Cloud Architect Company","publisher":{"@id":"https:\/\/www.easydeploy.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.easydeploy.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/www.easydeploy.io\/blog\/#organization","name":"EasyDeploy Technologies Pvt Ltd","url":"https:\/\/www.easydeploy.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.easydeploy.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2019\/02\/easydeploy.png","contentUrl":"https:\/\/www.easydeploy.io\/blog\/wp-content\/uploads\/2019\/02\/easydeploy.png","width":536,"height":100,"caption":"EasyDeploy Technologies Pvt Ltd"},"image":{"@id":"https:\/\/www.easydeploy.io\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/939543ac3b33fadea8b5115ab9a1280f","name":"Jerin Rathnam","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.easydeploy.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ca2c2ab4a28d380073334816b42aaa40?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ca2c2ab4a28d380073334816b42aaa40?s=96&d=mm&r=g","caption":"Jerin Rathnam"},"description":"Jerin Rathnam is a proficient DevOps engineer who is dedicated to streamlining software development and deployment processes. He has extensive knowledge of cloud infrastructure, containerization, and CI\/CD pipelines, which enables him to effectively connect development and operations. Jerin specializes in creating numerous Terraform modules for multi-cloud infrastructure and possesses immense expertise in configuring and managing cloud infrastructure. His profound understanding of containerization, along with his experience in orchestration tools like Docker and Kubernetes, further supports his skills as a valuable DevOps engineer.","sameAs":["https:\/\/www.gemjerin.site","https:\/\/www.facebook.com\/Jerinrathnam","https:\/\/www.instagram.com\/gem_jerin_rathnam\/","https:\/\/www.linkedin.com\/in\/jerin-rathnam\/","https:\/\/x.com\/jerin_rathnam","@jerinrathnam"],"url":"https:\/\/www.easydeploy.io\/blog\/author\/jerin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/posts\/1941"}],"collection":[{"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/comments?post=1941"}],"version-history":[{"count":7,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/posts\/1941\/revisions"}],"predecessor-version":[{"id":2037,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/posts\/1941\/revisions\/2037"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/media\/2410"}],"wp:attachment":[{"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/media?parent=1941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/categories?post=1941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.easydeploy.io\/blog\/wp-json\/wp\/v2\/tags?post=1941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}