How to use the @aws-cdk/core.Token.isUnresolved 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-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!
    };
  }
github aws / aws-cdk / packages / @aws-cdk / aws-sns-subscriptions / lib / url.ts View on Github external
constructor(private readonly url: string, private readonly props: UrlSubscriptionProps = {}) {
    this.unresolvedUrl = Token.isUnresolved(url);
    if (!this.unresolvedUrl && !url.startsWith('http://') && !url.startsWith('https://')) {
      throw new Error('URL must start with either http:// or https://');
    }

    if (this.unresolvedUrl && props.protocol === undefined) {
      throw new Error('Must provide protocol if url is unresolved');
    }

    if (this.unresolvedUrl) {
      this.protocol = props.protocol!;
    } else {
      this.protocol = this.url.startsWith('https:') ? sns.SubscriptionProtocol.HTTPS : sns.SubscriptionProtocol.HTTP;
    }
  }
github aws / aws-cdk / packages / @aws-cdk / aws-ec2 / lib / port.ts View on Github external
function renderPort(port: number) {
  return Token.isUnresolved(port) ? `{IndirectPort}` : port.toString();
}
github aws / aws-cdk / packages / @aws-cdk / aws-ecs / lib / fargate / fargate-task-definition.ts View on Github external
function stringifyNumber(x: number) {
  if (Token.isUnresolved(x)) {
    return Lazy.stringValue({ produce: context => `${context.resolve(x)}` });
  } else {
    return `${x}`;
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / pipeline.ts View on Github external
private requireRegion(): string {
    const region = Stack.of(this).region;
    if (Token.isUnresolved(region)) {
      throw new Error(`Pipeline stack which uses cross-environment actions must have an explicitly set region`);
    }
    return region;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-certificatemanager / lib / certificate.ts View on Github external
function domainValidationOption(domainName: string): CfnCertificate.DomainValidationOptionProperty {
      let validationDomain = props.validationDomains && props.validationDomains[domainName];
      if (validationDomain === undefined) {
        if (Token.isUnresolved(domainName)) {
          throw new Error(`When using Tokens for domain names, 'validationDomains' needs to be supplied`);
        }
        validationDomain = apexDomain(domainName);
      }

      return { domainName, validationDomain };
    }
  }
github aws / aws-cdk / packages / @aws-cdk / aws-route53 / lib / record-set.ts View on Github external
        : props.nameServers.map(ns => (Token.isUnresolved(ns) || ns.endsWith('.')) ? ns : `${ns}.`)
      ),
github aws / aws-cdk / packages / @aws-cdk / aws-ec2 / lib / peer.ts View on Github external
constructor(private readonly cidrIpv6: string) {
    if (!Token.isUnresolved(cidrIpv6)) {
      const cidrMatch = cidrIpv6.match(/^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/);

      if (!cidrMatch) {
        throw new Error(`Invalid IPv6 CIDR: "${cidrIpv6}"`);
      }

      if (!cidrMatch[3]) {
        throw new Error(`CIDR mask is missing in IPv6: "${cidrIpv6}". Did you mean "${cidrIpv6}/128"?`);
      }
    }

    this.uniqueId = cidrIpv6;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-ecr-assets / lib / image-asset.ts View on Github external
function validateBuildArgs(buildArgs?: { [key: string]: string }) {
  for (const [key, value] of Object.entries(buildArgs || {})) {
    if (Token.isUnresolved(key) || Token.isUnresolved(value)) {
      throw new Error(`Cannot use tokens in keys or values of "buildArgs" since they are needed before deployment`);
    }
  }
}