How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • // Extracts the function name out of an AWS Lambda Function ARN
    const arnComponents = stack.parseArn(arn, ":");
    const functionName = arnComponents.resourceName;
    
    Docs
    0
  • // test code
    const AWSMock = require("aws-sdk-mock");
    import AWS from "aws-sdk";
    AWSMock.setSDKInstance(AWS);
    AWSMock.mock("SQS" /* ... */);
    
    // implementation code
    const sqs = new AWS.SQS();
    
    Docs
    0
  • import AWSMock from "aws-sdk-mock";
    import AWS from "aws-sdk";
    import { GetItemInput } from "aws-sdk/clients/dynamodb";
    
    beforeAll(async (done) => {
      //get requires env vars
      done();
    });
    
    describe("the module", () => {
      /**
        TESTS below here
    **/
    
      it("should mock getItem from DynamoDB", async () => {
        // Overwriting DynamoDB.getItem()
        AWSMock.setSDKInstance(AWS);
        AWSMock.mock(
          "DynamoDB",
          "getItem",
          (params: GetItemInput, callback: Function) => {
            console.log("DynamoDB", "getItem", "mock called");
            callback(null, { pk: "foo", sk: "bar" });
          }
        );
    
        const input: GetItemInput = { TableName: "", Key: {} };
        const dynamodb = new AWS.DynamoDB({
          apiVersion: "2012-08-10",
        });
        expect(
          await dynamodb.getItem(input).promise()
        ).toStrictEqual({ pk: "foo", sk: "bar" });
    
        AWSMock.restore("DynamoDB");
      });
    
      it("should mock reading from DocumentClient", async () => {
        // Overwriting DynamoDB.DocumentClient.get()
        AWSMock.setSDKInstance(AWS);
        AWSMock.mock(
          "DynamoDB.DocumentClient",
          "get",
          (params: GetItemInput, callback: Function) => {
            console.log(
              "DynamoDB.DocumentClient",
              "get",
              "mock called"
            );
            callback(null, { pk: "foo", sk: "bar" });
          }
        );
    
        const input: GetItemInput = { TableName: "", Key: {} };
        const client = new AWS.DynamoDB.DocumentClient({
          apiVersion: "2012-08-10",
        });
        expect(await client.get(input).promise()).toStrictEqual(
          { pk: "foo", sk: "bar" }
        );
    
        AWSMock.restore("DynamoDB.DocumentClient");
      });
    });
    
    Docs
    0
  • // Builds "arn::lambda:::function:MyFunction"
    stack.formatArn({
      service: "lambda",
      resource: "function",
      sep: ":",
      resourceName: "MyFunction",
    });
    
    Docs
    0
  • function getOrCreate(scope: Construct): sns.Topic {
      const stack = Stack.of(scope);
      const uniqueid = "GloballyUniqueIdForSingleton"; // For example, a UUID from `uuidgen`
      return (
        (stack.node.tryFindChild(uniqueid) as sns.Topic) ??
        new sns.Topic(stack, uniqueid)
      );
    }
    
    Docs
    0
  • // "this" is the current construct
    const stack = Stack.of(this);
    
    stack.account; // Returns the AWS::AccountId for this stack (or the literal value if known)
    stack.region; // Returns the AWS::Region for this stack (or the literal value if known)
    stack.partition;
    
    Docs
    0
  • import { App, Stack } from "aws-cdk-lib";
    import { Bucket } from "aws-cdk-lib/aws-s3";
    
    const app = new App();
    const stack = new Stack(app, "TestStack");
    
    new Bucket(stack, "TestBucket");
    
    Docs
    0
  • import { Stack, App, aws_s3 as s3 } from "aws-cdk-lib";
    
    const app = new App();
    const stack = new Stack(app, "TestStack");
    
    new s3.Bucket(stack, "TestBucket");
    
    Docs
    0
  • const stack = new Stack(app, "StackName", {
      terminationProtection: true,
    });
    
    Docs
    0
  • const stack = new Stack(app, "StackName");
    
    stack.templateOptions.description =
      "This will appear in the AWS console";
    stack.templateOptions.transforms = [
      "AWS::Serverless-2016-10-31",
    ];
    stack.templateOptions.metadata = {
      metadataKey: "MetadataValue",
    };
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples