How to use the @aws-cdk/core.Resource function in @aws-cdk/core

To help you get started, we’ve selected a few @aws-cdk/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / @aws-cdk / aws-appmesh / lib / virtual-service.ts View on Github external
readonly virtualServiceName?: string;

  /**
   * The name of the service mesh that the virtual service resides in
   *
   * Used to derive ARN from mesh name if ARN not provided
   *
   * @default - Required if virtualServiceArn is not supplied.
   */
  readonly meshName?: string;
}

/**
 * Returns properties that allows a VirtualService to be imported
 */
class ImportedVirtualService extends cdk.Resource implements IVirtualService {
  /**
   * The name of the VirtualService, it is recommended this follows the fully-qualified domain name format.
   */
  public readonly virtualServiceName: string;

  /**
   * The Amazon Resource Name (ARN) for the virtual service
   */
  public readonly virtualServiceArn: string;

  constructor(scope: cdk.Construct, id: string, props: VirtualServiceAttributes) {
    super(scope, id);

    if (props.virtualServiceArn) {
      this.virtualServiceArn = props.virtualServiceArn;
      this.virtualServiceName = cdk.Fn.select(2, cdk.Fn.split('/', cdk.Stack.of(scope).parseArn(props.virtualServiceArn).resourceName!));
github aws / aws-cdk / packages / @aws-cdk / aws-ecs / lib / fargate / fargate-service.ts View on Github external
public static fromFargateServiceArn(scope: cdk.Construct, id: string, fargateServiceArn: string): IFargateService {
    class Import extends cdk.Resource implements IFargateService {
      public readonly serviceArn = fargateServiceArn;
    }
    return new Import(scope, id);
  }
github aws / aws-cdk / packages / @aws-cdk / aws-codedeploy / lib / lambda / deployment-group.ts View on Github external
/**
   * The physical, human-readable name of the CodeDeploy Lambda Deployment Group
   * that we are referencing.
   */
  readonly deploymentGroupName: string;

  /**
   * The Deployment Configuration this Deployment Group uses.
   *
   * @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
   */
  readonly deploymentConfig?: ILambdaDeploymentConfig;
}

class ImportedLambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploymentGroup {
  public readonly application: ILambdaApplication;
  public readonly deploymentGroupName: string;
  public readonly deploymentGroupArn: string;
  public readonly deploymentConfig: ILambdaDeploymentConfig;

  constructor(scope: cdk.Construct, id: string, props: LambdaDeploymentGroupAttributes) {
    super(scope, id);
    this.application = props.application;
    this.deploymentGroupName = props.deploymentGroupName;
    this.deploymentGroupArn = arnForDeploymentGroup(props.application.applicationName, props.deploymentGroupName);
    this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-ec2 / lib / vpn.ts View on Github external
*/
  IPSEC_1 = 'ipsec.1',

  /**
   * Dummy member
   * TODO: remove once https://github.com/aws/jsii/issues/231 is fixed
   */
  DUMMY = 'dummy'
}

/**
 * Define a VPN Connection
 *
 * @resource AWS::EC2::VPNConnection
 */
export class VpnConnection extends cdk.Resource implements IVpnConnection {
  /**
   * Return the given named metric for all VPN connections in the account/region.
   */
  public static metricAll(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
    return new cloudwatch.Metric({
      namespace: 'AWS/VPN',
      metricName,
      ...props
    });
  }

  /**
   * Metric for the tunnel state of all VPN connections in the account/region.
   *
   * @default average over 5 minutes
   */
github aws / aws-cdk / packages / @aws-cdk / aws-lambda / lib / event-source-mapping.ts View on Github external
readonly target: IFunction;
}

/**
 * Defines a Lambda EventSourceMapping resource.
 *
 * Usually, you won't need to define the mapping yourself. This will usually be done by
 * event sources. For example, to add an SQS event source to a function:
 *
 *    import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources';
 *    lambda.addEventSource(new SqsEventSource(sqs));
 *
 * The `SqsEventSource` class will automatically create the mapping, and will also
 * modify the Lambda's execution role so it can consume messages from the queue.
 */
export class EventSourceMapping extends cdk.Resource {
  constructor(scope: cdk.Construct, id: string, props: EventSourceMappingProps) {
    super(scope, id);

    if (props.maxBatchingWindow && props.maxBatchingWindow.toSeconds() > 300) {
      throw new Error(`maxBatchingWindow cannot be over 300 seconds, got ${props.maxBatchingWindow.toSeconds()}`);
    }

    new CfnEventSourceMapping(this, 'Resource', {
      batchSize: props.batchSize,
      enabled: props.enabled,
      eventSourceArn: props.eventSourceArn,
      functionName: props.target.functionName,
      startingPosition: props.startingPosition,
      maximumBatchingWindowInSeconds: props.maxBatchingWindow && props.maxBatchingWindow.toSeconds(),
    });
  }
github aws / aws-cdk / packages / @aws-cdk / aws-cloudfront / lib / origin_access_identity.ts View on Github external
* @default "Allows CloudFront to reach the bucket"
   */
  readonly comment?: string;
}

/**
 * Interface for CloudFront OriginAccessIdentity
 */
export interface IOriginAccessIdentity extends cdk.IResource, iam.IGrantable  {
  /**
   * The Origin Access Identity Name
   */
  readonly originAccessIdentityName: string;
}

abstract class OriginAccessIdentityBase extends cdk.Resource {
  /**
   * The Origin Access Identity Name (physical id)
   */
  public abstract readonly originAccessIdentityName: string;
  /**
   * Derived principal value for bucket access
   */
  public abstract readonly grantPrincipal: iam.IPrincipal;

  /**
   * The ARN to include in S3 bucket policy to allow CloudFront access
   */
  protected arn(): string {
    return cdk.Stack.of(this).formatArn(
      {
        service: "iam",
github aws / aws-cdk / packages / @aws-cdk / aws-appmesh / lib / mesh.ts View on Github external
/**
   * Adds a VirtualService with the given id
   */
  addVirtualService(id: string, props?: VirtualServiceBaseProps): VirtualService;

  /**
   * Adds a VirtualNode to the Mesh
   */
  addVirtualNode(id: string, props?: VirtualNodeBaseProps): VirtualNode;
}

/**
 * Represents a new or imported AppMesh mesh
 */
abstract class MeshBase extends cdk.Resource implements IMesh {
  /**
   * The name of the AppMesh mesh
   */
  public abstract readonly meshName: string;

  /**
   * The Amazon Resource Name (ARN) of the AppMesh mesh
   */
  public abstract readonly meshArn: string;

  /**
   * Adds a VirtualRouter to the Mesh with the given id and props
   */
  public addVirtualRouter(id: string, props: VirtualRouterBaseProps = {}): VirtualRouter {
    return new VirtualRouter(this, id, {
      ...props,
github aws / aws-cdk / packages / @aws-cdk / aws-appmesh / lib / virtual-node.ts View on Github external
* @default - No listeners
   */
  readonly listener?: VirtualNodeListener;
}

/**
 * The properties used when creating a new VirtualNode
 */
export interface VirtualNodeProps extends VirtualNodeBaseProps {
  /**
   * The name of the AppMesh which the virtual node belongs to
   */
  readonly mesh: IMesh;
}

abstract class VirtualNodeBase extends cdk.Resource implements IVirtualNode {
  /**
   * The name of the VirtualNode
   */
  public abstract readonly virtualNodeName: string;

  /**
   * The Amazon Resource Name belonging to the VirtualNdoe
   */
  public abstract readonly virtualNodeArn: string;

  protected readonly backends = new Array();
  protected readonly listeners = new Array();

  /**
   * Add a Virtual Services that this node is expected to send outbound traffic to
   */
github aws / aws-cdk / packages / @aws-cdk / aws-iam / lib / lazy-role.ts View on Github external
export interface LazyRoleProps extends RoleProps {

}

/**
 * An IAM role that only gets attached to the construct tree once it gets used, not before
 *
 * This construct can be used to simplify logic in other constructs
 * which need to create a role but only if certain configurations occur
 * (such as when AutoScaling is configured). The role can be configured in one
 * place, but if it never gets used it doesn't get instantiated and will
 * not be synthesized or deployed.
 *
 * @resource AWS::IAM::Role
 */
export class LazyRole extends cdk.Resource implements IRole {
  public readonly grantPrincipal: IPrincipal = this;
  public readonly assumeRoleAction: string = 'sts:AssumeRole';

  private role?: Role;
  private readonly statements = new Array();
  private readonly policies = new Array();
  private readonly managedPolicies = new Array();

  constructor(scope: cdk.Construct, id: string, private readonly props: LazyRoleProps) {
    super(scope, id);
  }

  /**
   * Adds a permission to the role's default policy document.
   * If there is no default policy attached to this role, it will be created.
   * @param statement The permission statement to add to the policy document
github aws / aws-cdk / packages / @aws-cdk / aws-codedeploy / lib / ecs / deployment-group.ts View on Github external
/**
   * The physical, human-readable name of the CodeDeploy ECS Deployment Group
   * that we are referencing.
   */
  readonly deploymentGroupName: string;

  /**
   * The Deployment Configuration this Deployment Group uses.
   *
   * @default EcsDeploymentConfig.ALL_AT_ONCE
   */
  readonly deploymentConfig?: IEcsDeploymentConfig;
}

class ImportedEcsDeploymentGroup extends cdk.Resource implements IEcsDeploymentGroup {
  public readonly application: IEcsApplication;
  public readonly deploymentGroupName: string;
  public readonly deploymentGroupArn: string;
  public readonly deploymentConfig: IEcsDeploymentConfig;

  constructor(scope: cdk.Construct, id: string, props: EcsDeploymentGroupAttributes) {
    super(scope, id);
    this.application = props.application;
    this.deploymentGroupName = props.deploymentGroupName;
    this.deploymentGroupArn = arnForDeploymentGroup(props.application.applicationName, props.deploymentGroupName);
    this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE;
  }
}