Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.