ResourceEnvironment

class aws_cdk.interfaces.ResourceEnvironment(*, account, region)

Bases: object

Represents the environment a given resource lives in.

Used as the return value for the IEnvironmentAware.env property.

Parameters:
  • account (str) – The AWS Account ID that this resource belongs to. Since this can be a Token (for example, when the account is CloudFormation’s AWS::AccountId intrinsic), make sure to use Token.compareStrings() instead of comparing the values with direct string equality.

  • region (str) – The AWS Region that this resource belongs to. Since this can be a Token (for example, when the region is CloudFormation’s AWS::Region intrinsic), make sure to use Token.compareStrings() instead of comparing the values with direct string equality.

ExampleMetadata:

nofixture infused

Example:

from aws_cdk.aws_iam import AddToResourcePolicyResult
from aws_cdk import CfnResource
from aws_cdk.aws_iam import IResourcePolicyFactory, IResourceWithPolicyV2, PolicyStatement, ResourceWithPolicies
from constructs import Construct, IConstruct

# scope: Construct
@jsii.implements(IResourcePolicyFactory)
class MyFactory:
    def for_resource(self, resource):
        return {
            "env": resource.env,
            def add_to_resource_policy(self, statement):
                # custom implementation to add the statement to the resource policy
                return AddToResourcePolicyResult("statement_added"=True, "policy_dependable"=resource)
        }

ResourceWithPolicies.register(scope, "AWS::KMS::Key", MyFactory())

Attributes

account

The AWS Account ID that this resource belongs to.

Since this can be a Token (for example, when the account is CloudFormation’s AWS::AccountId intrinsic), make sure to use Token.compareStrings() instead of comparing the values with direct string equality.

region

The AWS Region that this resource belongs to.

Since this can be a Token (for example, when the region is CloudFormation’s AWS::Region intrinsic), make sure to use Token.compareStrings() instead of comparing the values with direct string equality.