Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clickup/instance-to-ami-cdk

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clickup/instance-to-ami-cdk

A CDK construct to create an AMI from a healthy Instance time to time and update the Launch Template with it

  • 2.10.294
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

instance-to-ami-cdk: A CDK construct to create an AMI from a healthy Instance time to time and update the Launch Template with it

CI run

See also full API documentation.

The main idea behind InstanceToAmi CDK construct:

  1. It exposes an AWS Step Functions State Machine which, when run, takes a Snapshot of a running Instance's root EBS volume and creates an AMI Image from it. It's implied that you set up some automation on the instances which runs that State Machine time to time via AWS CLI.
  2. The assumption is that the Instance is a part of some Auto Scaling Group and is created using a Launch Template.
  3. Once the Image is created, the corresponding Launch Template is updated with it, and also, the Auto Scaling Group is updated to point to that new Launch Template version. So next time a new Instance is launched by that Auto Scaling Group, it will use the new Image.
  4. The tool keeps 2 previously created Snapshots/Images for backup purpose and removes the rest, and also removes all Launch Template versions which point to non-existing (removed) Images. It also sets up "fast snapshot restore" flag for the recent Snapshot, so the new Instances are created from the Image way faster. (And it resets this flag on backup Snapshots to save on costs.)
  5. The main feature: this is all done in a CDK drift-free manner. I.e. if you happen to update some Auto Scaling Group or Launch Template properties in CDK which also uses InstanceToAmi, then they will still refer to the Image assigned by the tool. But, if you change UserData, it will cause the Instances to be replaced as usual, and in that case, the Image in the Launch Template will be reset to the "main" one (all as expected).

Usage example in CDK (myASG of type AutoScalingGroup/CfnAutoScalingGroup and myLT of type LaunchTemplate/CfnLaunchTemplate should be created earlier in your CDK code):

class MyStack extends Stack {
  constructor(...) {
    ...
    const myLT = new LaunchTemplate(...); // or CfnLaunchTemplate
    const myASG = new AutoScalingGroup(...); // or CfnAutoScalingGroup
    ...
    new InstanceToAmi(this, "InstanceToAmi", {
      name: "instance-to-ami",
      autoScalingGroups: [{
        autoScalingGroup: myASG,
        launchTemplate: myLT,
      }],
      addToRoles: [myInstanceRole]
    });
  }
}

To execute that state machine on a healthy Instance:

aws lambda invoke \
  --function-name 'instance-to-ami' \
  --payload '{"instanceId":"i-1234567890","deps":"my-deps","minIntervalSec":3600}' \
  /dev/stdout | jq -s '.[0]'

Example of the result:

Or, if it's running already (concurrent runs protection):

You may optionally pass deps parameter which describes some post-boot downloadable state of the Instance (e.g. the list of Docker image ids downloaded by that Instance after it's booted). If the value of deps is seen the 1st time within the succeeded Executions, then the Lambda will not try to throttle the runs (i.e. "ran-recently-so-skipped" and "already-running" states will not happen, it will always start the Snapshot creation).

Generating a Snapshot and an Image typically takes ~10 minutes (it happens in background after the Lambda returns in ~5 seconds). In the end, the Launch Template and the Auto Scaling Group of the Instance you provided will be updated.

Other Tools

The library also exposes several helper functions useful in cloud-init scripts:

Keywords

FAQs

Package last updated on 26 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc