Skip to content
v2.274.0

CfnOutput L1 construct ​

Example ​

ts
declare const cluster: eks.Cluster;
// add service account
const serviceAccount = cluster.addServiceAccount('MyServiceAccount');

const bucket = new s3.Bucket(this, 'Bucket');
bucket.grantReadWrite(serviceAccount);

const mypod = cluster.addManifest('mypod', {
  apiVersion: 'v1',
  kind: 'Pod',
  metadata: { name: 'mypod' },
  spec: {
    serviceAccountName: serviceAccount.serviceAccountName,
    containers: [
      {
        name: 'hello',
        image: 'paulbouwer/hello-kubernetes:1.5',
        ports: [ { containerPort: 8080 } ],
      },
    ],
  },
});

// create the resource after the service account.
mypod.node.addDependency(serviceAccount);

// print the IAM role arn for this service account
new CfnOutput(this, 'ServiceAccountIamRole', { value: serviceAccount.role.roleArn });
python
# cluster: eks.Cluster

# add service account
service_account = cluster.add_service_account("MyServiceAccount")

bucket = s3.Bucket(self, "Bucket")
bucket.grant_read_write(service_account)

mypod = cluster.add_manifest("mypod", {
    "api_version": "v1",
    "kind": "Pod",
    "metadata": {"name": "mypod"},
    "spec": {
        "service_account_name": service_account.service_account_name,
        "containers": [{
            "name": "hello",
            "image": "paulbouwer/hello-kubernetes:1.5",
            "ports": [{"container_port": 8080}]
        }
        ]
    }
})

# create the resource after the service account.
mypod.node.add_dependency(service_account)

# print the IAM role arn for this service account
CfnOutput(self, "ServiceAccountIamRole", value=service_account.role.role_arn)
java
Cluster cluster;

// add service account
ServiceAccount serviceAccount = cluster.addServiceAccount("MyServiceAccount");

Bucket bucket = new Bucket(this, "Bucket");
bucket.grantReadWrite(serviceAccount);

KubernetesManifest mypod = cluster.addManifest("mypod", Map.of(
        "apiVersion", "v1",
        "kind", "Pod",
        "metadata", Map.of("name", "mypod"),
        "spec", Map.of(
                "serviceAccountName", serviceAccount.getServiceAccountName(),
                "containers", List.of(Map.of(
                        "name", "hello",
                        "image", "paulbouwer/hello-kubernetes:1.5",
                        "ports", List.of(Map.of("containerPort", 8080)))))));

// create the resource after the service account.
mypod.node.addDependency(serviceAccount);

// print the IAM role arn for this service account
// print the IAM role arn for this service account
CfnOutput.Builder.create(this, "ServiceAccountIamRole").value(serviceAccount.getRole().getRoleArn()).build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;

// add service account
var serviceAccount = cluster.AddServiceAccount("MyServiceAccount");

var bucket = new Bucket(this, "Bucket");
bucket.GrantReadWrite(serviceAccount);

var mypod = cluster.AddManifest("mypod", new Dictionary<string, object> {
    { "apiVersion", "v1" },
    { "kind", "Pod" },
    { "metadata", new Dictionary<string, string> { { "name", "mypod" } } },
    { "spec", new Dictionary<string, object> {
        { "serviceAccountName", serviceAccount.ServiceAccountName },
        { "containers", new [] { new Struct {
            Name = "hello",
            Image = "paulbouwer/hello-kubernetes:1.5",
            Ports = new [] { new Struct { ContainerPort = 8080 } }
        } } }
    } }
});

// create the resource after the service account.
mypod.Node.AddDependency(serviceAccount);

// print the IAM role arn for this service account
// print the IAM role arn for this service account
new CfnOutput(this, "ServiceAccountIamRole", new CfnOutputProps { Value = serviceAccount.Role.RoleArn });
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster

// add service account
serviceAccount := cluster.addServiceAccount(jsii.String("MyServiceAccount"))

bucket := s3.NewBucket(this, jsii.String("Bucket"))
bucket.GrantReadWrite(serviceAccount)

mypod := cluster.addManifest(jsii.String("mypod"), map[string]interface{}{
	"apiVersion": jsii.String("v1"),
	"kind": jsii.String("Pod"),
	"metadata": map[string]*string{
		"name": jsii.String("mypod"),
	},
	"spec": map[string]interface{}{
		"serviceAccountName": serviceAccount.serviceAccountName,
		"containers": []map[string]interface{}{
			map[string]interface{}{
				"name": jsii.String("hello"),
				"image": jsii.String("paulbouwer/hello-kubernetes:1.5"),
				"ports": []map[string]*f64{
					map[string]*f64{
						"containerPort": jsii.Number(8080),
					},
				},
			},
		},
	},
})

// create the resource after the service account.
mypod.Node.AddDependency(serviceAccount)

// print the IAM role arn for this service account
// print the IAM role arn for this service account
awscdk.NewCfnOutput(this, jsii.String("ServiceAccountIamRole"), &CfnOutputProps{
	Value: serviceAccount.Role.RoleArn,
})

Initializer ​

ts
new CfnOutput(scope: Construct, id: string, props: CfnOutputProps)
python
CfnOutput(scope: Construct, id: str, props: CfnOutputProps)
java
new CfnOutput(Construct scope, String id, CfnOutputProps props)
csharp
new CfnOutput(Construct scope, string id, CfnOutputProps props)
go
NewCfnOutput(Scope Construct, Id *string, Props CfnOutputProps)

Construct Props ​

conditionoptionalCfnConditionconditionoptionalCfnConditionconditionoptionalCfnConditionConditionoptionalCfnConditionConditionoptionalCfnCondition#
A condition to associate with this output value.

Default: No condition is associated with the output.

If the condition evaluates to false, this output value will not be included in the stack.

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string#
A String type that describes the output value.

Default: No description.

The description can be a maximum of 4 K in length.

exportNameoptionalstringexport_nameoptionalstrexportNameoptionalStringExportNameoptionalstringExportNameoptional*string#
The name used to export the value of this output across stacks.

Default: the output is not exported

To import the value from another stack, use Fn.importValue(exportName).

keyoptionalstringkeyoptionalstrkeyoptionalStringKeyoptionalstringKeyoptional*string#
The key of the property returned by aws cloudformation describe-stacks command.
valuestringvaluestrvalueStringValuestringValue*stringrequired#
The value of the property returned by the aws cloudformation describe-stacks command.

The value of an output can include literals, parameter references, pseudo-parameters, a mapping value, or intrinsic functions.

Properties ​

conditionmay be undefinedCfnConditionconditionmay be undefinedCfnConditionconditionmay be undefinedCfnConditionConditionmay be undefinedCfnConditionConditionmay be undefinedCfnCondition#
A condition to associate with this output value.

Default: No condition is associated with the output.

If the condition evaluates to false, this output value will not be included in the stack.

creationStackstring[]creation_stacktyping.List[str]creationStackList<String>CreationStackstring[]CreationStack*[]*stringrequired#
descriptionmay be undefinedstringdescriptionmay be undefinedstrdescriptionmay be undefinedStringDescriptionmay be undefinedstringDescriptionmay be undefined*string#
A String type that describes the output value.

Default: No description.

The description can be a maximum of 4 K in length.

exportNamemay be undefinedstringexport_namemay be undefinedstrexportNamemay be undefinedStringExportNamemay be undefinedstringExportNamemay be undefined*string#
The name used to export the value of this output across stacks.

Default: the output is not exported

To use the value in another stack, pass the value of output.importValue to it.

importValuestringimport_valuestrimportValueStringImportValuestringImportValue*stringrequired#
Return the `Fn.importValue` expression to import this value into another stack.
notes

The returned value should not be used in the same stack, but in a different one. It must be deployed to the same environment, as CloudFormation exports can only be imported in the same Region and account.

The is no automatic registration of dependencies between stacks when using this mechanism, so you should make sure to deploy them in the right order yourself.

You can use this mechanism to share values across Stacks in different Stages. If you intend to share the value to another Stack inside the same Stage, the automatic cross-stack referencing mechanism is more convenient.

logicalIdstringlogical_idstrlogicalIdStringLogicalIdstringLogicalId*stringrequired#
The logical ID for this CloudFormation stack element.

The logical ID of the element is calculated from the path of the resource node in the construct tree.

To override this value, use overrideLogicalId(newLogicalId).

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this element is defined.

CfnElements must be defined within a stack scope (directly or indirectly).

valueanyvalueAnyvalueObjectValueobjectValueinterface{}required#
The value of the property returned by the aws cloudformation describe-stacks command.

The value of an output can include literals, parameter references, pseudo-parameters, a mapping value, or intrinsic functions.

Methods ​

isCfnElement(x: any): boolean@staticmethod def is_cfn_element(x: Any) -> boolpublic static Boolean isCfnElement(Object x)public static bool IsCfnElement(object x)func IsCfnElement(X interface{}) *boolstatic#
Returns `true` if a construct is a stack element (i.e. part of the synthesized cloudformation template).

Uses duck-typing instead of instanceof to allow stack elements from different versions of this library to be included in the same stack.

returns

Returns: The construct as a stack element or undefined if it is not a stack element.

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

overrideLogicalId(newLogicalId: string): voiddef override_logical_id(self, new_logical_id: str) -> Nonepublic void overrideLogicalId(String newLogicalId)public void OverrideLogicalId(string newLogicalId)func OverrideLogicalId(NewLogicalId *string)#
Overrides the auto-generated logical ID with a specific ID.
1 parameter

Parameters

  • newLogicalIdnew_logical_idnewLogicalIdnewLogicalIdNewLogicalId — The new logical ID to use for this stack element.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.