aws-cdk-lib#Names TypeScript Examples

The following examples show how to use aws-cdk-lib#Names. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: runServerless.ts    From lift with MIT License 6 votes vote down vote up
computeLogicalId = (serverless: Serverless, ...address: string[]): string => {
    const initialNode = serverless.stack.node;
    const foundNode = [...address].reduce((currentNode, nextNodeId) => {
        const nextNode = currentNode.tryFindChild(nextNodeId);
        if (!nextNode) {
            const existingNodes = currentNode.children.map((child) => child.node.id).join(", ");
            throw new Error(
                `No node named ${nextNodeId} found in ${address.join(".")} address. Existing nodes: ${existingNodes}`
            );
        }

        return nextNode.node;
    }, initialNode);

    // Some CDK constructs have a sub-node called `Resource`, some others don't
    const resourceNode = foundNode.tryFindChild("Resource");
    if (resourceNode) {
        return Names.nodeUniqueId(resourceNode.node);
    }

    return Names.nodeUniqueId(foundNode);
}
Example #2
Source File: index.ts    From cloudstructs with Apache License 2.0 5 votes vote down vote up
constructor(scope: Construct, id: string, props: SamlIdentityProviderProps) {
    super(scope, id);

    const name = props.name ?? `${Names.uniqueId(this)}IdentityProvider`;

    const arn = Stack.of(this).formatArn({
      service: 'iam',
      region: '',
      resource: 'saml-provider',
      resourceName: name,
    });

    const idp = new cr.AwsCustomResource(this, 'Resource', {
      resourceType: 'Custom::SamlIdentityProvider',
      onCreate: {
        service: 'IAM',
        action: 'createSAMLProvider',
        parameters: {
          Name: name,
          SAMLMetadataDocument: props.metadataDocument,
        } as IAM.CreateSAMLProviderRequest,
        physicalResourceId: cr.PhysicalResourceId.fromResponse('SAMLProviderArn'),
      },
      onUpdate: {
        service: 'IAM',
        action: 'updateSAMLProvider',
        parameters: {
          SAMLProviderArn: new cr.PhysicalResourceIdReference().toJSON(),
          SAMLMetadataDocument: props.metadataDocument,
        } as IAM.UpdateSAMLProviderRequest,
        physicalResourceId: cr.PhysicalResourceId.fromResponse('SAMLProviderArn'),
      },
      onDelete: {
        service: 'IAM',
        action: 'deleteSAMLProvider',
        parameters: {
          SAMLProviderArn: new cr.PhysicalResourceIdReference().toJSON(),
        } as IAM.DeleteSAMLProviderRequest,
      },
      policy: cr.AwsCustomResourcePolicy.fromStatements([
        new iam.PolicyStatement({
          actions: [
            'iam:createSAMLProvider',
            'iam:updateSAMLProvider',
            'iam:deleteSAMLProvider',
          ],
          resources: [arn],
        }),
      ]),
    });

    this.samlIdentityProviderArn = idp.getResponseField('SAMLProviderArn');
  }