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

  • import {
      Construct,
      CustomResource,
      CustomResourceProvider,
      CustomResourceProviderRuntime,
      Token,
    } from '@aws-cdk/core';
    
    export interface SumProps {
      readonly lhs: number;
      readonly rhs: number;
    }
    
    export class Sum extends Construct {
      public readonly result: number;
    
      constructor(scope: Construct, id: string, props: SumProps) {
        super(scope, id);
    
        const resourceType = 'Custom::Sum';
        const serviceToken = CustomResourceProvider.getOrCreate(this, resourceType, {
          codeDirectory: `${__dirname}/sum-handler`,
          runtime: CustomResourceProviderRuntime.NODEJS_12_X,
        });
    
        const resource = new CustomResource(this, 'Resource', {
          resourceType: resourceType,
          serviceToken: serviceToken,
          properties: {
            lhs: props.lhs,
            rhs: props.rhs
          }
        });
    
        this.result = Token.asNumber(resource.getAtt('Result'));
      }
    }
    
    Docs
    0
  • const sum = new Sum(this, 'MySum', { lhs: 40, rhs: 2 });
    new CfnOutput(this, 'Result', { value: Token.asString(sum.result) });
    
    Docs
    0
  • fileSystem.connections.allowDefaultPortFrom(instance);
    
    instance.userData.addCommands("yum check-update -y",    // Ubuntu: apt-get -y update
      "yum upgrade -y",                                 // Ubuntu: apt-get -y upgrade
      "yum install -y amazon-efs-utils",                // Ubuntu: apt-get -y install amazon-efs-utils
      "yum install -y nfs-utils",                       // Ubuntu: apt-get -y install nfs-common
      "file_system_id_1=" + fileSystem.fileSystemId,
      "efs_mount_point_1=/mnt/efs/fs1",
      "mkdir -p \"${efs_mount_point_1}\"",
      "test -f \"/sbin/mount.efs\" && echo \"${file_system_id_1}:/ ${efs_mount_point_1} efs defaults,_netdev\" >> /etc/fstab || " +
      "echo \"${file_system_id_1}.efs." + Stack.of(this).region + ".amazonaws.com:/ ${efs_mount_point_1} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0\" >> /etc/fstab",
      "mount -a -t efs,nfs4 defaults");
    
    Docs
    0
  • const bus = new events.EventBus(this, 'bus', {
      eventBusName: 'MyCustomEventBus'
    });
    
    bus.archive('MyArchive', {
      archiveName: 'MyCustomEventBusArchive',
      description: 'MyCustomerEventBus Archive',
      eventPattern: {
        account: [Stack.of(this).account],
      },
      retention: Duration.days(365),
    });
    
    Docs
    0
  • import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2';
    const httpApi = new apigatewayv2.HttpApi(this, 'MyHttpApi');
    
    const invokeTask = new tasks.CallApiGatewayHttpApiEndpoint(this, 'Call HTTP API', {
      apiId: httpApi.apiId,
      apiStack: Stack.of(httpApi),
      method: tasks.HttpMethod.GET,
    });
    
    Docs
    0
  • const subZone = new route53.PublicHostedZone(this, 'SubZone', {
      zoneName: 'sub.someexample.com',
    });
    
    // import the delegation role by constructing the roleArn
    const delegationRoleArn = Stack.of(this).formatArn({
      region: '', // IAM is global in each partition
      service: 'iam',
      account: 'parent-account-id',
      resource: 'role',
      resourceName: 'MyDelegationRole',
    });
    const delegationRole = iam.Role.fromRoleArn(this, 'DelegationRole', delegationRoleArn);
    
    // create the record
    new route53.CrossAccountZoneDelegationRecord(this, 'delegate', {
      delegatedZone: subZone,
      parentHostedZoneName: 'someexample.com', // or you can use parentHostedZoneId
      delegationRole,
    });
    
    Docs
    0
  • // The code below shows an example of how to instantiate this type.
    // The values are placeholders you should change.
    import * as cdk from '@aws-cdk/core';
    
    const tag = new cdk.Tag('key', 'value', /* all optional props */ {
      applyToLaunchedInstances: false,
      excludeResourceTypes: ['excludeResourceTypes'],
      includeResourceTypes: ['includeResourceTypes'],
      priority: 123,
    });
    
    Docs
    0
  • import { App, CfnOutput, NestedStack, NestedStackProps, Stack } from '@aws-cdk/core';
    import { Construct } from 'constructs';
    import { Deployment, Method, MockIntegration, PassthroughBehavior, RestApi, Stage } from '../lib';
    
    /**
     * This file showcases how to split up a RestApi's Resources and Methods across nested stacks.
     *
     * The root stack 'RootStack' first defines a RestApi.
     * Two nested stacks BooksStack and PetsStack, create corresponding Resources '/books' and '/pets'.
     * They are then deployed to a 'prod' Stage via a third nested stack - DeployStack.
     *
     * To verify this worked, go to the APIGateway
     */
    
    class RootStack extends Stack {
      constructor(scope: Construct) {
        super(scope, 'integ-restapi-import-RootStack');
    
        const restApi = new RestApi(this, 'RestApi', {
          deploy: false,
        });
        restApi.root.addMethod('ANY');
    
        const petsStack = new PetsStack(this, {
          restApiId: restApi.restApiId,
          rootResourceId: restApi.restApiRootResourceId,
        });
        const booksStack = new BooksStack(this, {
          restApiId: restApi.restApiId,
          rootResourceId: restApi.restApiRootResourceId,
        });
        new DeployStack(this, {
          restApiId: restApi.restApiId,
          methods: petsStack.methods.concat(booksStack.methods),
        });
    
        new CfnOutput(this, 'PetsURL', {
          value: `https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/pets`,
        });
    
        new CfnOutput(this, 'BooksURL', {
          value: `https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/books`,
        });
      }
    }
    
    interface ResourceNestedStackProps extends NestedStackProps {
      readonly restApiId: string;
    
      readonly rootResourceId: string;
    }
    
    class PetsStack extends NestedStack {
      public readonly methods: Method[] = [];
    
      constructor(scope: Construct, props: ResourceNestedStackProps) {
        super(scope, 'integ-restapi-import-PetsStack', props);
    
        const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
          restApiId: props.restApiId,
          rootResourceId: props.rootResourceId,
        });
    
        const method = api.root.addResource('pets').addMethod('GET', new MockIntegration({
          integrationResponses: [{
            statusCode: '200',
          }],
          passthroughBehavior: PassthroughBehavior.NEVER,
          requestTemplates: {
            'application/json': '{ "statusCode": 200 }',
          },
        }), {
          methodResponses: [{ statusCode: '200' }],
        });
    
        this.methods.push(method);
      }
    }
    
    class BooksStack extends NestedStack {
      public readonly methods: Method[] = [];
    
      constructor(scope: Construct, props: ResourceNestedStackProps) {
        super(scope, 'integ-restapi-import-BooksStack', props);
    
        const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
          restApiId: props.restApiId,
          rootResourceId: props.rootResourceId,
        });
    
        const method = api.root.addResource('books').addMethod('GET', new MockIntegration({
          integrationResponses: [{
            statusCode: '200',
          }],
          passthroughBehavior: PassthroughBehavior.NEVER,
          requestTemplates: {
            'application/json': '{ "statusCode": 200 }',
          },
        }), {
          methodResponses: [{ statusCode: '200' }],
        });
    
        this.methods.push(method);
      }
    }
    
    interface DeployStackProps extends NestedStackProps {
      readonly restApiId: string;
    
      readonly methods?: Method[];
    }
    
    class DeployStack extends NestedStack {
      constructor(scope: Construct, props: DeployStackProps) {
        super(scope, 'integ-restapi-import-DeployStack', props);
    
        const deployment = new Deployment(this, 'Deployment', {
          api: RestApi.fromRestApiId(this, 'RestApi', props.restApiId),
        });
        if (props.methods) {
          for (const method of props.methods) {
            deployment.node.addDependency(method);
          }
        }
        new Stage(this, 'Stage', { deployment });
      }
    }
    
    new RootStack(new App());
    
    Docs
    0
  • const app = new cdk.App();
    const stack = new cdk.Stack(app, 'stack');
    
    Docs
    0
  • const app = new App();
    const stack = new Stack(app, 'AwsCdkFsxLustreImport');
    
    const sg = SecurityGroup.fromSecurityGroupId(stack, 'FsxSecurityGroup', '{SECURITY-GROUP-ID}');
    const fs = LustreFileSystem.fromLustreFileSystemAttributes(stack, 'FsxLustreFileSystem', {
        dnsName: '{FILE-SYSTEM-DNS-NAME}'
        fileSystemId: '{FILE-SYSTEM-ID}',
        securityGroup: sg
    });
    
    const vpc = Vpc.fromVpcAttributes(stack, 'Vpc', {
        availabilityZones: ['us-west-2a', 'us-west-2b'],
        publicSubnetIds: ['{US-WEST-2A-SUBNET-ID}', '{US-WEST-2B-SUBNET-ID}'],
        vpcId: '{VPC-ID}'
    });
    const inst = new Instance(stack, 'inst', {
      instanceType: InstanceType.of(InstanceClass.T2, InstanceSize.LARGE),
      machineImage: new AmazonLinuxImage({
        generation: AmazonLinuxGeneration.AMAZON_LINUX_2
      }),
      vpc,
      vpcSubnets: {
        subnetType: SubnetType.PUBLIC,
      }
    });
    fs.connections.allowDefaultPortFrom(inst);
    
    Docs
    0
  • const app = new App();
    const stack = new Stack(app, 'AwsCdkFsxLustre');
    const vpc = new Vpc(stack, 'VPC');
    
    const lustreConfiguration = {
      deploymentType: LustreDeploymentType.SCRATCH_2,
    };
    const fs = new LustreFileSystem(stack, 'FsxLustreFileSystem', {
      lustreConfiguration,
      storageCapacityGiB: 1200,
      vpc,
      vpcSubnet: vpc.privateSubnets[0]});
    
    const inst = new Instance(stack, 'inst', {
      instanceType: InstanceType.of(InstanceClass.T2, InstanceSize.LARGE),
      machineImage: new AmazonLinuxImage({
        generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
      }),
      vpc,
      vpcSubnets: {
        subnetType: SubnetType.PUBLIC,
      },
    });
    fs.connections.allowDefaultPortFrom(inst);
    
    // Need to give the instance access to read information about FSx to determine the file system's mount name.
    inst.role.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('AmazonFSxReadOnlyAccess'));
    
    const mountPath = '/mnt/fsx';
    const dnsName = fs.dnsName;
    const mountName = fs.mountName;
    
    inst.userData.addCommands(
      'set -eux',
      'yum update -y',
      'amazon-linux-extras install -y lustre2.10',
      // Set up the directory to mount the file system to and change the owner to the AL2 default ec2-user.
      `mkdir -p ${mountPath}`,
      `chmod 777 ${mountPath}`,
      `chown ec2-user:ec2-user ${mountPath}`,
      // Set the file system up to mount automatically on start up and mount it.
      `echo "${dnsName}@tcp:/${mountName} ${mountPath} lustre defaults,noatime,flock,_netdev 0 0" >> /etc/fstab`,
      'mount -a');
    
    Docs
    0
  • const app = new App();
    const stack = new Stack(app, 'MyStack');
    sfn.StateMachine.fromStateMachineArn(
      stack,
      'ImportedStateMachine',
      'arn:aws:states:us-east-1:123456789012:stateMachine:StateMachine2E01A3A5-N5TJppzoevKQ',
    );
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples