Skip to content

Instantly share code, notes, and snippets.

@ntamvl
Last active February 17, 2023 15:56
Show Gist options
  • Save ntamvl/7d7ce2e0ad8c5742e3cd87de76e6906b to your computer and use it in GitHub Desktop.
Save ntamvl/7d7ce2e0ad8c5742e3cd87de76e6906b to your computer and use it in GitHub Desktop.
Example: use aws-sdk-mock to test AWS SSM

Use aws-sdk-mock to test AWS SSM

Example:

const AWSMock = require("aws-sdk-mock");
import AWS = require("aws-sdk");
AWSMock.setSDKInstance(AWS);

import "mocha";
import { expect } from "chai";

const base_url = "test.yourdomain.com";
const host = `https://${base_url}`;
const path = "/api/user";

describe("TEST SSM", function() {
  it("should mock SSM getParameter", async () => {
    // Overwriting SSM getParameter()
    AWSMock.setSDKInstance(AWS);
    AWSMock.mock("SSM", "getParameter", {
      Parameter: {
        Name: "/order/main/endpoint/base-url",
        Type: "String",
        Value: base_url,
        Version: 1,
        LastModifiedDate: 1562226288.85,
        ARN: "arn:aws:ssm:us-west-1:123:/order/main/endpoint/base-url"
      }
    });

    const ssm = new AWS.SSM();
    const params = {
      Name: "/order/main/endpoint/base-url",
      WithDecryption: false
    };
    const result = await ssm.getParameter(params).promise();
    const value = result.Parameter ? result.Parameter.Value : "";

    expect(result.Parameter).to.be.an("object");
    expect(value).to.equal(base_url);

    AWSMock.restore("SSM");
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment