How to use the @aws-cdk/core.Lazy.stringValue 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-iam / lib / managed-policy.ts View on Github external
public static fromAwsManagedPolicyName(managedPolicyName: string): IManagedPolicy {
    class AwsManagedPolicy implements IManagedPolicy {
      public readonly managedPolicyArn = Lazy.stringValue({
        produce(ctx: IResolveContext) {
          return Stack.of(ctx.scope).formatArn({
            service: "iam",
            region: "", // no region for managed policy
            account: "aws", // the account for a managed policy is 'aws'
            resource: "policy",
            resourceName: managedPolicyName
          });
        }
      });
    }
    return new AwsManagedPolicy();
  }
github aws / aws-cdk / packages / @aws-cdk / aws-codebuild / lib / project.ts View on Github external
this.addSecondaryArtifact(secondaryArtifact);
    }

    this.validateCodePipelineSettings(artifacts);

    const resource = new CfnProject(this, 'Resource', {
      description: props.description,
      source: {
        ...sourceConfig.sourceProperty,
        buildSpec: buildSpec && buildSpec.toBuildSpec()
      },
      artifacts: artifactsConfig.artifactsProperty,
      serviceRole: this.role.roleArn,
      environment: this.renderEnvironment(props.environment, environmentVariables),
      // lazy, because we have a setter for it in setEncryptionKey
      encryptionKey: Lazy.stringValue({ produce: () => this._encryptionKey && this._encryptionKey.keyArn }),
      badgeEnabled: props.badge,
      cache: cache._toCloudFormation(),
      name: this.physicalName,
      timeoutInMinutes: props.timeout && props.timeout.toMinutes(),
      secondarySources: Lazy.anyValue({ produce: () => this.renderSecondarySources() }),
      secondaryArtifacts: Lazy.anyValue({ produce: () => this.renderSecondaryArtifacts() }),
      triggers: sourceConfig.buildTriggers,
      vpcConfig: this.configureVpc(props),
    });

    this.addVpcRequiredPermissions(props, resource);

    this.projectArn = this.getResourceArnAttribute(resource.attrArn, {
      service: 'codebuild',
      resource: 'project',
      resourceName: this.physicalName,
github aws / aws-cdk / packages / @aws-cdk / aws-ec2 / lib / vpc.ts View on Github external
this.availabilityZone = props.availabilityZone;
    const subnet = new CfnSubnet(this, 'Subnet', {
      vpcId: props.vpcId,
      cidrBlock: props.cidrBlock,
      availabilityZone: props.availabilityZone,
      mapPublicIpOnLaunch: props.mapPublicIpOnLaunch,
    });
    this.subnetId = subnet.ref;
    this.subnetVpcId = subnet.attrVpcId;
    this.subnetAvailabilityZone = subnet.attrAvailabilityZone;
    this.subnetIpv6CidrBlocks = subnet.attrIpv6CidrBlocks;

    // subnet.attrNetworkAclAssociationId is the default ACL after the subnet
    // was just created. However, the ACL can be replaced at a later time.
    this._networkAcl = NetworkAcl.fromNetworkAclId(this, 'Acl', subnet.attrNetworkAclAssociationId);
    this.subnetNetworkAclAssociationId = Lazy.stringValue({ produce: () => this._networkAcl.networkAclId });
    this.node.defaultChild = subnet;

    const table = new CfnRouteTable(this, 'RouteTable', {
      vpcId: props.vpcId,
    });
    this.routeTable = { routeTableId: table.ref };

    // Associate the public route table for this subnet, to this subnet
    new CfnSubnetRouteTableAssociation(this, 'RouteTableAssociation', {
      subnetId: this.subnetId,
      routeTableId: table.ref
    });

    this.internetConnectivityEstablished = this._internetConnectivityEstablished;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-autoscaling / lib / auto-scaling-group.ts View on Github external
this.role = props.role || new iam.Role(this, 'InstanceRole', {
      roleName: PhysicalName.GENERATE_IF_NEEDED,
      assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
    });

    this.grantPrincipal = this.role;

    const iamProfile = new iam.CfnInstanceProfile(this, 'InstanceProfile', {
      roles: [ this.role.roleName ]
    });

    // use delayed evaluation
    const imageConfig = props.machineImage.getImage(this);
    this.userData = props.userData || imageConfig.userData || ec2.UserData.forOperatingSystem(imageConfig.osType);
    const userDataToken = Lazy.stringValue({ produce: () => Fn.base64(this.userData.render()) });
    const securityGroupsToken = Lazy.listValue({ produce: () => this.securityGroups.map(sg => sg.securityGroupId) });

    const launchConfig = new CfnLaunchConfiguration(this, 'LaunchConfig', {
      imageId: imageConfig.imageId,
      keyName: props.keyName,
      instanceType: props.instanceType.toString(),
      securityGroups: securityGroupsToken,
      iamInstanceProfile: iamProfile.ref,
      userData: userDataToken,
      associatePublicIpAddress: props.associatePublicIpAddress,
      spotPrice: props.spotPrice,
      blockDeviceMappings: (props.blockDevices !== undefined ? props.blockDevices.map(
          ({deviceName, volume, mappingEnabled}) => {
            const {virtualName, ebsDevice: ebs} = volume;

            if (ebs) {
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 / 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-apigateway / lib / vpc-link.ts View on Github external
constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
    super(scope, id, {
      physicalName: props.vpcLinkName ||
        Lazy.stringValue({ produce: () => this.node.uniqueId }),
    });

    const cfnResource = new CfnVpcLink(this, 'Resource', {
      name: this.physicalName,
      description: props.description,
      targetArns: Lazy.listValue({ produce: () => this.renderTargets() })
    });

    this.vpcLinkId = cfnResource.ref;

    if (props.targets) {
      this.addTargets(...props.targets);
    }
  }
github aws / aws-cdk / packages / @aws-cdk / aws-events / lib / rule.ts View on Github external
constructor(scope: Construct, id: string, props: RuleProps = { }) {
    super(scope, id, {
      physicalName: props.ruleName,
    });
    this.description = props.description;

    const resource = new CfnRule(this, 'Resource', {
      name: this.physicalName,
      description: this.description,
      state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'),
      scheduleExpression: Lazy.stringValue({ produce: () => this.scheduleExpression }),
      eventPattern: Lazy.anyValue({ produce: () => this.renderEventPattern() }),
      targets: Lazy.anyValue({ produce: () => this.renderTargets() }),
    });

    this.ruleArn = this.getResourceArnAttribute(resource.attrArn, {
      service: 'events',
      resource: 'rule',
      resourceName: this.physicalName,
    });

    this.addEventPattern(props.eventPattern);
    this.scheduleExpression = props.schedule && props.schedule.expressionString;

    for (const target of props.targets || []) {
      this.addTarget(target);
    }
github aws / aws-cdk / packages / @aws-cdk / aws-config / lib / managed-rules.ts View on Github external
constructor(scope: Construct, id: string, props: CloudFormationStackDriftDetectionCheckProps = {}) {
    super(scope, id, {
      ...props,
      identifier: 'CLOUDFORMATION_STACK_DRIFT_DETECTION_CHECK',
      inputParameters: {
        cloudformationRoleArn: Lazy.stringValue({ produce: () => this.role.roleArn })
      }
    });

    this.scopeToResource('AWS::CloudFormation::Stack', props.ownStackOnly ? Stack.of(this).stackId : undefined);

    this.role = props.role || new iam.Role(this, 'Role', {
      assumedBy: new iam.ServicePrincipal('config.amazonaws.com'),
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('ReadOnlyAccess')
      ]
    });
  }
}