aws-lambda#CloudFormationCustomResourceEvent TypeScript Examples

The following examples show how to use aws-lambda#CloudFormationCustomResourceEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From aws-cdk-ses-domain-identity with MIT License 6 votes vote down vote up
export async function identityRequestHandler(event: CloudFormationCustomResourceEvent) {
  const handler: CustomResourceHandler = (() => {
    switch (event.RequestType) {
      case "Create":
        return new CreateCustomResourceHandler(event);
      case "Update":
        return new UpdateCustomResourceHandler(event);
      case "Delete":
        return new DeleteCustomResourceHandler(event);
    }
  })();

  return await handler.handleEvent();
}
Example #2
Source File: base.test.ts    From aws-cdk-ses-domain-identity with MIT License 5 votes vote down vote up
describe(CustomResourceHandler.name, () => {
  let event: CloudFormationCustomResourceEvent;
  beforeEach(() => {
    event = {
      StackId: "StackId",
      RequestId: "RequestId",
      LogicalResourceId: "LogicalResourceId",
      RequestType: "Fake",
      ResponseURL: "https://s3.amazonaws.com/bucket/key",
    } as any;
  });

  describe("#handleEvent", () => {
    it("should report success if consumeEvent was resolved", async () => {
      const request = nock("https://s3.amazonaws.com")
        .put("/bucket/key", (body) => body.Status === "SUCCESS")
        .reply(200);

      const handler = new SuccessfulCustomResourceHandler(event);
      const res = await handler.handleEvent();
      expect(request.isDone()).toBeTruthy();
      expect(res).toEqual({
        Status: "SUCCESS",
        PhysicalResourceId: "id",
        StackId: "StackId",
        RequestId: "RequestId",
        LogicalResourceId: "LogicalResourceId",
        Data: { Name: "Value" },
      });
    });

    it("should report failure if consumeEvent thrown an error", async () => {
      const request = nock("https://s3.amazonaws.com")
        .put("/bucket/key", (body) => body.Status === "FAILED")
        .reply(200);

      const handler = new FailureCustomResourceHandler(event);
      const res = await handler.handleEvent();
      expect(request.isDone()).toBeTruthy();
      expect(res).toEqual({
        Status: "FAILED",
        Reason: "MOCKED ERROR",
        PhysicalResourceId: "Unknown",
        StackId: "StackId",
        RequestId: "RequestId",
        LogicalResourceId: "LogicalResourceId",
        Data: {},
      });
    });
  });
});