How to use @aws-cdk/core - 10 common examples

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 customink / activerecord-aurora-serverless-adapter / test / aurora-serverless / lib / aurora-serverless-stack.ts View on Github external
// SECRETS

    const secret = new CfnSecret(
      this,
      "Secret",
      secretProps(aurora, DB_CLUSTER_ID)
    );
    const secret2 = new CfnSecret(
      this,
      "Secret2",
      secretProps(aurora2, `${DB_CLUSTER_ID}2`)
    );
    secret.addDependsOn(aurora);
    secret2.addDependsOn(aurora2);
    new CfnOutput(this, "AASASecretArn", {
      value: secret.ref
    });
    new CfnOutput(this, "AASASecretArn2", {
      value: secret2.ref
    });

    // TEST USER

    const user = new User(this, "TestUser");
    const policy = new Policy(this, "TestUserPolicy", {
      statements: [
        new PolicyStatement({
          actions: ["rds-data:*"],
          resources: [
            `arn:aws:rds:${this.region}:${this.account}:cluster:${DB_CLUSTER_ID}*`,
            `arn:aws:rds:${this.region}:${this.account}:cluster:${DB_CLUSTER_ID}2*`
github aws / aws-cdk / packages / @aws-cdk / aws-cloudformation / lib / nested-stack.ts View on Github external
super(scope, id, { env: { account: parentStack.account, region: parentStack.region } });

    // @deprecate: remove this in v2.0 (redundent)
    const parentScope = new Construct(scope, id + '.NestedStack');

    Object.defineProperty(this, NESTED_STACK_SYMBOL, { value: true });

    // this is the file name of the synthesized template file within the cloud assembly
    this.templateFile = `${this.node.uniqueId}.nested.template.json`;

    this.parameters = props.parameters || {};

    this.resource = new CfnStack(parentScope, `${id}.NestedStackResource`, {
      templateUrl: this.templateUrl,
      parameters: Lazy.anyValue({ produce: () => Object.keys(this.parameters).length > 0 ? this.parameters : undefined }),
      notificationArns: props.notifications ? props.notifications.map(n => n.topicArn) : undefined,
      timeoutInMinutes: props.timeout ? props.timeout.toMinutes() : undefined,
    });

    this.nestedStackResource = this.resource;

    // context-aware stack name: if resolved from within this stack, return AWS::StackName
    // if resolved from the outer stack, use the { Ref } of the AWS::CloudFormation::Stack resource
    // which resolves the ARN of the stack. We need to extract the stack name, which is the second
    // component after splitting by "/"
    this._contextualStackName = this.contextualAttribute(Aws.STACK_NAME, Fn.select(1, Fn.split('/', this.resource.ref)));
    this._contextualStackId = this.contextualAttribute(Aws.STACK_ID, this.resource.ref);
  }
github punchcard / punchcard / examples / lib / invoke-function.ts View on Github external
count: 1,
        anyProperty: {
          this: 'property can be any type supported by the AWS.DynamoDB.DocumentClient',
        }
      },
      if: item => DynamoDB.attribute_not_exists(item.id)
    });
    newCount = 1;
  }
  return newCount;
});

// call the incrementer function from another Lambda Function
Lambda.schedule(stack, 'Caller', {
  depends: incrementer.invokeAccess(),
  schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, incrementer) => {
  const newCount = await incrementer.invoke({
    id: 'id'
  });
  console.log(`new count of 'id' is ${newCount}`);
});
github aws / aws-cdk / packages / @aws-cdk / aws-apigateway / lib / method.ts View on Github external
}

    if (options.connectionType === ConnectionType.VPC_LINK && options.vpcLink === undefined) {
      throw new Error(`'connectionType' of VPC_LINK requires 'vpcLink' prop to be set`);
    }

    if (options.connectionType === ConnectionType.INTERNET && options.vpcLink !== undefined) {
      throw new Error(`cannot set 'vpcLink' where 'connectionType' is INTERNET`);
    }

    if (options.credentialsRole) {
      credentials = options.credentialsRole.roleArn;
    } else if (options.credentialsPassthrough) {
      // arn:aws:iam::*:user/*
      // tslint:disable-next-line:max-line-length
      credentials = Stack.of(this).formatArn({ service: 'iam', region: '', account: '*', resource: 'user', sep: '/', resourceName: '*' });
    }

    return {
      type: integration._props.type,
      uri: integration._props.uri,
      cacheKeyParameters: options.cacheKeyParameters,
      cacheNamespace: options.cacheNamespace,
      contentHandling: options.contentHandling,
      integrationHttpMethod: integration._props.integrationHttpMethod,
      requestParameters: options.requestParameters,
      requestTemplates: options.requestTemplates,
      passthroughBehavior: options.passthroughBehavior,
      integrationResponses: options.integrationResponses,
      connectionType: options.connectionType,
      connectionId: options.vpcLink ? options.vpcLink.vpcLinkId : undefined,
      credentials,
github aws / aws-cdk / packages / @aws-cdk / aws-ecs-patterns / lib / base / queue-processing-service-base.ts View on Github external
protected getDefaultCluster(scope: Construct, vpc?: IVpc): Cluster {
    // magic string to avoid collision with user-defined constructs
    const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
    const stack = Stack.of(scope);
    return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
  }
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / pipeline.ts View on Github external
private renderArtifactStoresProperty(): CfnPipeline.ArtifactStoreMapProperty[] | undefined {
    if (!this.crossRegion) { return undefined; }

    // add the Pipeline's artifact store
    const primaryRegion = this.requireRegion();
    this._crossRegionSupport[primaryRegion] = {
      replicationBucket: this.artifactBucket,
      stack: Stack.of(this),
    };

    return Object.entries(this._crossRegionSupport).map(([region, support]) => ({
      region,
      artifactStore: this.renderArtifactStore(support.replicationBucket),
    }));
  }
github aws / aws-cdk / packages / @aws-cdk / aws-secretsmanager / lib / secret.ts View on Github external
const result = iam.Grant.addToPrincipal({
      grantee,
      actions: ['secretsmanager:GetSecretValue'],
      resourceArns: [this.secretArn],
      scope: this
    });
    if (versionStages != null && result.principalStatement) {
      result.principalStatement.addCondition('ForAnyValue:StringEquals', {
        'secretsmanager:VersionStage': versionStages
      });
    }

    if (this.encryptionKey) {
      // @see https://docs.aws.amazon.com/fr_fr/kms/latest/developerguide/services-secrets-manager.html
      this.encryptionKey.grantDecrypt(
        new kms.ViaServicePrincipal(`secretsmanager.${Stack.of(this).region}.amazonaws.com`, grantee.grantPrincipal)
      );
    }

    return result;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / pipeline.ts View on Github external
private getOtherStackIfActionIsCrossAccount(action: IAction): Stack | undefined {
    const pipelineStack = Stack.of(this);

    if (action.actionProperties.resource) {
      const resourceStack = Stack.of(action.actionProperties.resource);
      // check if resource is from a different account
      if (pipelineStack.account === resourceStack.account) {
        return undefined;
      } else {
        this._crossAccountSupport[resourceStack.account] = resourceStack;
        return resourceStack;
      }
    }

    if (!action.actionProperties.account) {
      return undefined;
    }
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / pipeline.ts View on Github external
this._crossAccountSupport[resourceStack.account] = resourceStack;
        return resourceStack;
      }
    }

    if (!action.actionProperties.account) {
      return undefined;
    }

    const targetAccount = action.actionProperties.account;
    // check whether the account is a static string
    if (Token.isUnresolved(targetAccount)) {
      throw new Error(`The 'account' property must be a concrete value (action: '${action.actionProperties.actionName}')`);
    }
    // check whether the pipeline account is a static string
    if (Token.isUnresolved(pipelineStack.account)) {
      throw new Error("Pipeline stack which uses cross-environment actions must have an explicitly set account");
    }

    if (pipelineStack.account === targetAccount) {
      return undefined;
    }

    let targetAccountStack: Stack | undefined = this._crossAccountSupport[targetAccount];
    if (!targetAccountStack) {
      const stackId = `cross-account-support-stack-${targetAccount}`;
      const app = this.requireApp();
      targetAccountStack = app.node.tryFindChild(stackId) as Stack;
      if (!targetAccountStack) {
        targetAccountStack = new Stack(app, stackId, {
          stackName: `${pipelineStack.stackName}-support-${targetAccount}`,
          env: {
github aws / aws-cdk / packages / @aws-cdk / aws-ec2 / lib / vpc.ts View on Github external
constructor(scope: Construct, id: string, attrs: SubnetAttributes) {
    super(scope, id);

    if (!attrs.routeTableId) {
      const ref = Token.isUnresolved(attrs.subnetId)
        ? `at '${scope.node.path}/${id}'`
        : `'${attrs.subnetId}'`;
      // tslint:disable-next-line: max-line-length
      scope.node.addWarning(`No routeTableId was provided to the subnet ${ref}. Attempting to read its .routeTable.routeTableId will return null/undefined. (More info: https://github.com/aws/aws-cdk/pull/3171)`);
    }

    this.availabilityZone = attrs.availabilityZone;
    this.subnetId = attrs.subnetId;
    this.routeTable = {
      // Forcing routeTableId to pretend non-null to maintain backwards-compatibility. See https://github.com/aws/aws-cdk/pull/3171
      routeTableId: attrs.routeTableId!
    };
  }