npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnet/aws-ssm-commander

v0.1.3

Published

This project is designed to streamline command execution on AWS EC2 instances using AWS Systems Manager (SSM). It allows users to either send a command to a specific instance or find the instance via a CloudFormation stack output, simplifying the process

Downloads

185

Readme

@fnet/aws-ssm-commander

This project is designed to streamline command execution on AWS EC2 instances using AWS Systems Manager (SSM). It allows users to either send a command to a specific instance or find the instance via a CloudFormation stack output, simplifying the process of managing EC2 resources directly from the command line.

How It Works

Simply put, the project verifies your AWS identity, identifies the target EC2 instance either directly or through CloudFormation, and executes the specified command on the instance via the SSM service. The tool waits for the command to execute and then returns the result, making the task of remote management straightforward.

Key Features

  • AWS Identity Verification: Confirms and logs the user's AWS account information.
  • Instance Identification: Retrieves the EC2 instance ID from AWS CloudFormation stack outputs if not provided directly.
  • Command Execution: Uses AWS SSM to run commands on your EC2 instances.
  • Polling for Results: Regularly checks and retrieves the command execution results.

Conclusion

The @fnet/aws-ssm-commander is a simple, effective way to manage and execute commands on AWS EC2 instances without the need for direct SSH access. By leveraging CloudFormation and SSM, it provides a flexible approach to managing AWS resources, particularly useful for those looking to automate tasks or manage instances programmatically.

Developer Guide for @fnet/aws-ssm-commander

Overview

The @fnet/aws-ssm-commander library provides a convenient way for developers to execute shell commands on AWS EC2 instances via AWS Systems Manager (SSM). This can be particularly useful for automation tasks, configuration management, and managing instances remotely without direct SSH access. The library abstracts the complexity of retrieving instance information from CloudFormation and executing commands through SSM.

Installation

To install the @fnet/aws-ssm-commander library, use either npm or yarn:

npm install @fnet/aws-ssm-commander

or

yarn add @fnet/aws-ssm-commander

Usage

The library exports a single asynchronous function, making it straightforward to use. You'll need to provide AWS credentials and permissions that allow access to STS, SSM, and optionally CloudFormation, depending on your use case.

Below is a step-by-step example of how to use the library to execute a command on an EC2 instance:

Examples

Executing a Command on an EC2 Instance

Suppose you want to run a shell command on an EC2 instance identified by a CloudFormation stack output. Here's how you can achieve that:

import executeSSMCommand from '@fnet/aws-ssm-commander';

(async () => {
  try {
    const output = await executeSSMCommand({
      stackName: 'my-cloudformation-stack', // Name of your CloudFormation stack
      command: 'echo "Hello, World!"', // Command to run on the instance
      region: 'us-west-2', // AWS region
      verbose: true // Optional logging for visibility
    });

    console.log('Command Output:', output);
  } catch (error) {
    console.error('Error executing command:', error.message);
  }
})();

Directly Using an Instance ID

If you already know the instance ID and don't need to look it up from a CloudFormation stack, you can directly specify it:

import executeSSMCommand from '@fnet/aws-ssm-commander';

(async () => {
  try {
    const output = await executeSSMCommand({
      instanceId: 'i-0abcd1234efgh5678', // Direct EC2 instance ID
      command: ['uptime', 'df -h'], // Array of commands to run
      region: 'us-east-1' // AWS region
    });

    console.log('Command Outputs:', output);
  } catch (error) {
    console.error('Error executing command:', error.message);
  }
})();

Acknowledgement

This library is powered by AWS SDK clients for STS, SSM, and CloudFormation, making it essential to ensure that AWS permissions are correctly configured for these services.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  env:
    type: object
    description: AWS credentials configuration.
    oneOf:
      - properties:
          AWS_PROFILE:
            type: string
            description: AWS Profile Name.
        required:
          - AWS_PROFILE
      - properties:
          AWS_ACCESS_KEY_ID:
            type: string
            description: AWS Access Key ID.
          AWS_SECRET_ACCESS_KEY:
            type: string
            description: AWS Secret Access Key.
          AWS_SESSION_TOKEN:
            type: string
            description: AWS Session Token.
        required:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
  instanceId:
    type: string
    description: The EC2 instance ID (if provided, skips CloudFormation lookup).
  stackName:
    type: string
    description: The name of the CloudFormation stack (used if instanceId is not provided).
  outputKey:
    type: string
    description: The CloudFormation output key to locate the InstanceID.
    default: InstanceID
  command:
    oneOf:
      - type: string
        description: A single command to execute on the EC2 instance.
      - type: array
        items:
          type: string
        description: An array of commands to execute on the EC2 instance.
  region:
    type: string
    description: The AWS region.
  parameters:
    type: array
    items:
      type: string
    description: Optional parameters for the command.
    default: []
  pollingInterval:
    type: number
    description: The interval in milliseconds to poll for command status.
    default: 5000
required:
  - command
  - region
allOf:
  - if:
      not:
        properties:
          instanceId:
            type: string
    then:
      required:
        - stackName