Automatic EC2 instance AMI Creation and Deletion

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • AWS Automatic EC2 Instance AMI (Amazon Machine Image) Creation and Deletion.
    Automating the AMI Creation and Deletion of the EC2 instances.
    We Followed the below link for this process.
    www.webdigi.co...
    1). Create the policy as Lambda_execution_Policy
    Use following link for the policy
    github.com/web...
    2). Create the IAM role with name: - Lambda_Execution_Role and attach the above created policy
    3) Create the Lambda function by name CreateAmi and use the above created role with this lambda function.
    4) Click on Create Function
    5). Now Open your lambda function and paste the following script.
    Use following link for copying the CreateAmi script
    github.com/web...
    Please remember to Change your Region in the Script. The Region you will select for your EC2 instance Deployed.
    6). Set the Timeout as 5 minutes.
    7). Click on the save button on top right corner.
    8). Now create the DeleteAMI function using above steps.
    9). Paste the following DeleteAMI function.
    Use Following link for copying the script of DeleteAMI
    github.com/web...
    Please Remember to change the region of your EC2 instance in the script
    10). Set the timeout to 5 minutes and click on Save button on the top right corner.
    11). Create the Rule for scheduling your Ami creation and Ami Deletion
    12). Click on Cloudwatch, click on Rules. Click on scheduled expression.
    13). Set your AMI Create timing in UTC format. For example if you want to create the AMI daily at 12.00 AM midnight as per the IST. Then the UTC expression for this would be
    30 18 * * ? * (at 18 Hrs. 30 Min. UTC every day of month, every month, every weekdays every year)
    14). Select the lambda function you created as target. Name the rule and save it.
    15). Similarly create the Cloudwatch Rule for Deleting the Ami using above steps.
    16). Now just Add the tags to your EC2 Instances.
    Key Value
    Backup Yes
    BackupNoReboot true
    BackupRetentionDays 7
    The above tags actually will enable the automatic Ami creation and Deletion of your EC2 instances.
    The backup tag enables the AMI Backup,
    BackupNoReboot with value true will disable the auto reboot of your EC2 instance during the process of AMI Creation.
    BackupRetentionDays the value of this tag will determine how many days you want to keep the Ami and snapshots of the EC2 instances. On the basis of this Retention days the Delete Ami function deletes the older Ami and snapshots.

ความคิดเห็น • 4

  • @jorgelazaro2510
    @jorgelazaro2510 9 วันที่ผ่านมา

    What exactly are you doing? I want to learn more about aws

    • @mirzafaisalbaig
      @mirzafaisalbaig  9 วันที่ผ่านมา

      @@jorgelazaro2510 I am automating virtual machine backup and deletion of the backup.

    • @jorgelazaro2510
      @jorgelazaro2510 9 วันที่ผ่านมา

      @ do you have advice to learn aws?

    • @mirzafaisalbaig
      @mirzafaisalbaig  7 วันที่ผ่านมา

      @jorgelazaro2510 I would recommend beginners should learn from Ryan croonenberg.