How to use the @aws-cdk/core.Token.asString 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-eks / lib / kubectl-layer.ts View on Github external
this.stack.templateOptions.transforms = [ 'AWS::Serverless-2016-10-31' ]; // required for AWS::Serverless
    const resource = new CfnResource(this, 'Resource', {
      type: 'AWS::Serverless::Application',
      properties: {
        Location: {
          ApplicationId: KUBECTL_APP_ARN,
          SemanticVersion: version
        },
        Parameters: {
          LayerName: `kubectl-${uniqueId}`
        }
      }
    });

    this.layerVersionArn = Token.asString(resource.getAtt('Outputs.LayerVersionArn'));
  }
github aws / aws-cdk / packages / @aws-cdk / aws-cloudformation / lib / nested-stack.ts View on Github external
protected prepareCrossReference(sourceStack: Stack, reference: Reference): IResolvable {
    const targetStack = Stack.of(reference.target);

    // the nested stack references a resource from the parent stack:
    // we pass it through a as a cloudformation parameter
    if (targetStack === sourceStack.nestedStackParent) {
      // we call "this.resolve" to ensure that tokens do not creep in (for example, if the reference display name includes tokens)
      const paramId = this.resolve(`reference-to-${reference.target.node.uniqueId}.${reference.displayName}`);
      let param = this.node.tryFindChild(paramId) as CfnParameter;
      if (!param) {
        param = new CfnParameter(this, paramId, { type: 'String' });
        this.parameters[param.logicalId] = Token.asString(reference);
      }

      return param.value;
    }

    // parent stack references a resource from the nested stack:
    // we output it from the nested stack and use "Fn::GetAtt" as the reference value
    if (targetStack === this && targetStack.nestedStackParent === sourceStack) {
      return this.getCreateOutputForReference(reference);
    }

    // sibling nested stacks (same parent):
    // output from one and pass as parameter to the other
    if (targetStack.nestedStackParent && targetStack.nestedStackParent === sourceStack.nestedStackParent) {
      const outputValue = this.getCreateOutputForReference(reference);
      return (sourceStack as NestedStack).prepareCrossReference(sourceStack, outputValue);
github aws / aws-cdk / packages / @aws-cdk / aws-cloudformation / lib / nested-stack.ts View on Github external
private contextualAttribute(innerValue: string, outerValue: string) {
    return Token.asString({
      resolve: (context: IResolveContext) => {
        if (Stack.of(context.scope) === this) {
          return innerValue;
        } else {
          return outerValue;
        }
      }
    });
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / artifact.ts View on Github external
function artifactGetParam(artifact: Artifact, jsonFile: string, keyName: string) {
  const lazyArtifactName = Lazy.stringValue({ produce: () => artifact.artifactName });
  return Token.asString({ 'Fn::GetParam': [lazyArtifactName, jsonFile, keyName] });
}
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / artifact.ts View on Github external
function artifactAttribute(artifact: Artifact, attributeName: string) {
  const lazyArtifactName = Lazy.stringValue({ produce: () => artifact.artifactName });
  return Token.asString({ 'Fn::GetArtifactAtt': [lazyArtifactName, attributeName] });
}
github aws / aws-cdk / packages / @aws-cdk / aws-eks / lib / cluster-resource.ts View on Github external
handler.addToRolePolicy(new iam.PolicyStatement({
      actions: [ 'iam:PassRole' ],
      resources: [ props.roleArn ]
    }));

    const resource = new cfn.CustomResource(this, 'Resource', {
      resourceType: ClusterResource.RESOURCE_TYPE,
      provider: cfn.CustomResourceProvider.lambda(handler),
      properties: {
        Config: props
      }
    });

    this.ref = resource.ref;
    this.attrEndpoint = Token.asString(resource.getAtt('Endpoint'));
    this.attrArn = Token.asString(resource.getAtt('Arn'));
    this.attrCertificateAuthorityData = Token.asString(resource.getAtt('CertificateAuthorityData'));
    this.creationRole = handler.role!;
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-stepfunctions / lib / json-path.ts View on Github external
public toString() {
    return Token.asString(this, { displayHint: this.displayHint });
  }
github aws / aws-cdk / packages / @aws-cdk / aws-cloudformation / lib / custom-resource.ts View on Github external
public getAttString(attributeName: string): string {
    return Token.asString(this.getAtt(attributeName));
  }
}