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

serverless-plugin-ssm-document

v2.3.5

Published

Serverless plugin to easily create SSM documents

Downloads

34

Readme

Serverless SSM documents

npm

A serverless plugin to easily create SSM document from configurations and script files.

Usage

Installation

$ npm install serverless-plugin-ssm-document --save-dev

or using yarn

$ yarn add serverless-plugin-ssm-document

Configuration

plugins:
  - serverless-plugin-ssm-document

custom:
  ssmDocuments:

    dropCache:
      description: Drop system cache # document description
      workingDirectory: /tmp # working directory used by command
      scriptFile: ./ssm/dropCache/script.sh
      tags:
        MyTagKey: MyTagValue # tags object will be merged wil global "provider.tags" configuration

    cleanCache:
      name: ${self:provider.stage, opt:stage}-CleanCache # document name, default is key config name (e.g. CleanCache)
      description: Clean system temporary directory 
      parameters: 
        Directory: # parameters can be configured here
          type: String
          default: test
      scriptFile: ./ssm/cleanCache/script.sh
    
    checkCache:
      name: ${self:provider.stage, opt:stage}-CheckCache
      description: Check cache size
      parameters: ${file(./ssm/checkCache/parameters.yml)} # or in a separate file
      scriptFile: ./ssm/checkCache/script.sh # script file must be a valid file path
      accountIds:
        - 00000000 # share documents to specific AWS account ids
    
    performCacheTest:
      description: Public Test Cache
      scriptFile: ./ssm/testCache/script.sh
      accountIds:
        - 'all' # set account to 'all' to make it public

Parameters

Refer to SSM Document Syntax for Parameters. For example you can include an external file parameters.yml that contain the follow:

Directory: # parameter name (is the key of config object)
  type: String # parameter type
  default: test # parameter default value
  allowedPattern: "^(?!\/).*.[^\/]$" # regular expression to filter value
  description: "(Optional) Temporary directory, must not start or end with a slash." # parameter description

please prepend '(Optional) ' to optional parameters description to better understand this difference.

Script file

Script file can be a simple shell script, it will be executed using aws-runShellScript plugin.

#!/bin/bash

echo "$(date +'%F-%T') executing tmp directory cleaning.."
rm -rf /tmp/{{ Directory }}/*
echo "$(date +'%F-%T') tmp directory '{{ Directory }}' cleaned successfully!"

interpolate a parameter using {{ }} syntax and refer parameter by its own name {{ ParameterName }}.

SSM Command Name

This plugin will name your command based on configuration key, for example:

custom:
  ssmDocuments:
    cleanCache:
      description: Clean system temporary directory
      scriptFile: ./ssm/cleanCache/script.sh

deployed with "test" as stage name:

serverless deploy --stage=test

will name your SSM document to "stage-CleanCache". If you want to override this behaviour simply add name property to your SSM command:

custom:
  ssmDocuments:
    cleanCache:
      name: CleanSystemCache
      description: Clean system temporary directory
      scriptFile: ./ssm/cleanCache/script.sh

Pay attention when you name you SSM command to not collide with other SSM documents:

serverless deploy --stage=test

will name your SSM document to "CleanSystemCache". If you run deploy on the same AWS account but with a different stage name:

serverless deploy --stage=prod

will fail due a resource name collision since "CleanSystemCache" already exists

Resources Created

This plugin will create one AWS::SSM::Document for each ssmDocuments configurations keys.

CloudFormation resources can be referenced using your configuration key name, converted in camel-case (my-command -> MyCommand) and appended "SSMDocument", for example:

custom:
  ssmDocuments:
    cleanCache:
      # document configurations

will create the follow resource:

{
  "Resources": {
    "CleanCacheSSMDocument": {
      // document configurations
    }
  }
}

can be referenced in this way:

iamRoleStatements:
  - Effect: Allow
    Action:
      - ssm:SendCommand
    Resource:
      Ref: CleanCacheSSMDocument

IAM Permissions

IAM user that perform deploy need to have the following policy attached:

{
  "Sid": "DeploySSMDocumentPermission",
  "Effect": "Allow",
  "Action": [
      "ssm:DescribeDocument",
      "ssm:DescribeDocumentPermission",
      "ssm:CreateDocument",
      "ssm:ModifyDocumentPermission",
      "ssm:DeleteDocument"
  ],
  "Resource": "*"
}

Debug

To enable debug output set DEBUG environment variable to "yes" and execute package command:

export DEBUG="yes"
serverless package

or deploy command:

export DEBUG="yes"
serverless deploy --stage=test