### Define AWS CDK Application (Single File) Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md Illustrates a standard AWS CDK application defining an S3 bucket and exporting its name as a CfnOutput. This setup is typical for a single-repository or single-file scenario where direct access is trivial. ```typescript import * as aws from 'aws-cdk-lib'; const awsApp = new aws.App(); const stack = new aws.Stack(awsApp, 'aws'); const bucket = new aws.aws_s3.Bucket(stack, 'Bucket'); const bucketName = new aws.CfnOutput(stack, 'BucketName', { value: bucket.bucketName, }); awsApp.synth(); ``` -------------------------------- ### Consume AWS CDK Output in cdk8s Application Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md This example demonstrates how a cdk8s application imports the `bucketName` instance from the published `my-cdk-app` package. It utilizes `AwsCdkResolver` to dynamically resolve the `CfnOutput` value at synthesis time and injects it into a Kubernetes `CronJob`'s environment variable, enabling cross-repository data sharing. ```typescript import * as k8s from 'cdk8s'; import * as kplus from 'cdk8s-plus-27'; // import the desired instance from the AWS CDK app. import { bucketName } from 'my-cdk-app'; import { AwsCdkResolver } from '@cdk8s/awscdk-resolver'; const k8sApp = new k8s.App({ resolvers: [new AwsCdkResolver()] }); const manifest = new k8s.Chart(k8sApp, 'Manifest'); new kplus.CronJob(manifest, 'CronJob', { schedule: k8s.Cron.daily(), containers: [{ image: 'job', envVariables: { // directly passing the value of the `CfnOutput` containing // the deploy time bucket name BUCKET_NAME: kplus.EnvValue.fromValue(bucketName.value), } }] }); k8sApp.synth(); ``` -------------------------------- ### Resolve AWS CDK CfnOutput in cdk8s with AwsCdkResolver (TypeScript) Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md This TypeScript example demonstrates how to use the `AwsCdkResolver` to fetch the name of an AWS S3 Bucket, defined as a `CfnOutput` in an AWS CDK application, and pass it as an environment variable to a Kubernetes `CronJob` managed by cdk8s. It shows the integration of AWS CDK constructs with cdk8s resources, allowing deploy-time values to be consumed by Kubernetes manifests. The resolver performs AWS API calls during `cdk8s synth` to retrieve the actual output value. ```typescript import * as aws from 'aws-cdk-lib'; import * as k8s from 'cdk8s'; import * as kplus from 'cdk8s-plus-27'; import { AwsCdkResolver } from '@cdk8s/awscdk-resolver'; const awsApp = new aws.App(); const stack = new aws.Stack(awsApp, 'aws'); const k8sApp = new k8s.App({ resolvers: [new AwsCdkResolver()] }); const manifest = new k8s.Chart(k8sApp, 'Manifest'); const bucket = new aws.aws_s3.Bucket(stack, 'Bucket'); const bucketName = new aws.CfnOutput(stack, 'BucketName', { value: bucket.bucketName, }); new kplus.CronJob(manifest, 'CronJob', { schedule: k8s.Cron.daily(), containers: [{ image: 'job', envVariables: { // directly passing the value of the `CfnOutput` containing // the deploy time bucket name BUCKET_NAME: kplus.EnvValue.fromValue(bucketName.value), } }] }); awsApp.synth(); k8sApp.synth(); ``` -------------------------------- ### Initialize AwsCdkResolver Class Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/API.md Demonstrates how to instantiate the `AwsCdkResolver` class, which implements the `cdk8s.IResolver` interface. This constructor takes no parameters. ```typescript import { AwsCdkResolver } from '@cdk8s/awscdk-resolver' new AwsCdkResolver() ``` -------------------------------- ### Synthesize AWS CDK Application (main.ts) Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md The `main.ts` file serves as the entry point for synthesizing the AWS CDK application. It imports the `awsApp` instance from `app.ts` and calls `synth()` to generate the CloudFormation template. This separation allows `app.ts` to be published as a standalone package. ```typescript import { awsApp } from './app.ts' awsApp.synth(); ``` -------------------------------- ### AwsCdkResolver Class API Reference Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/API.md Detailed API documentation for the `AwsCdkResolver` class, outlining its implemented interfaces, constructor, and the `resolve` method with its parameters and purpose. ```APIDOC AwsCdkResolver: Implements: cdk8s.IResolver Initializers: new AwsCdkResolver(): Parameters: (None) Methods: resolve(context: ResolutionContext): void Description: This function is invoked on every property during cdk8s synthesis. To replace a value, implementations must invoke `context.replaceValue`. Parameters: context: Type: cdk8s.ResolutionContext Required: true ``` -------------------------------- ### Prepare AWS CDK Application for Cross-Repository Export Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md This snippet shows how to refactor the AWS CDK application into `app.ts` to export the `CfnOutput` instance directly. This makes the instance available for consumption by other applications via a package manager. Crucially, `awsApp.synth()` is omitted here, as synthesis will be handled by a separate entry point. ```typescript import * as aws from 'aws-cdk-lib'; const awsApp = new aws.App(); const stack = new aws.Stack(awsApp, 'aws'); const bucket = new aws.aws_s3.Bucket(stack, 'Bucket'); // export the thing we want to have available for cdk8s applications export const bucketName = new aws.CfnOutput(stack, 'BucketName', { value: bucket.bucketName, }); // note that we don't call awsApp.synth here ``` -------------------------------- ### Required AWS Permissions for AwsCdkResolver (APIDOC) Source: https://github.com/cdk8s-team/cdk8s-awscdk-resolver/blob/main/README.md Details the minimum AWS IAM permissions required for the `AwsCdkResolver` to function correctly. These permissions are necessary for `cdk8s synth` to perform `cloudformation:DescribeStacks` calls to fetch `CfnOutput` values from deployed AWS CDK stacks. ```APIDOC - `cloudformation:DescribeStacks` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.