Skip to content
v2.278.0

AccountPrincipal ​

Class Stable

Specify AWS account ID as the principal entity in a policy to delegate authority to the account.

Example ​

ts
const cluster = new neptune.DatabaseCluster(this, 'Cluster', {
  vpc,
  instanceType: neptune.InstanceType.R5_LARGE,
  iamAuthentication: true, // Optional - will be automatically set if you call grantConnect() or grant().
});
const role = new iam.Role(this, 'DBRole', { assumedBy: new iam.AccountPrincipal(this.account) });
// Use one of the following statements to grant the role the necessary permissions
cluster.grantConnect(role); // Grant the role neptune-db:* access to the DB
cluster.grant(role, 'neptune-db:ReadDataViaQuery', 'neptune-db:WriteDataViaQuery'); // Grant the role the specified actions to the DB
python
cluster = neptune.DatabaseCluster(self, "Cluster",
    vpc=vpc,
    instance_type=neptune.InstanceType.R5_LARGE,
    iam_authentication=True
)
role = iam.Role(self, "DBRole", assumed_by=iam.AccountPrincipal(self.account))
# Use one of the following statements to grant the role the necessary permissions
cluster.grant_connect(role) # Grant the role neptune-db:* access to the DB
cluster.grant(role, "neptune-db:ReadDataViaQuery", "neptune-db:WriteDataViaQuery")
java
DatabaseCluster cluster = DatabaseCluster.Builder.create(this, "Cluster")
        .vpc(vpc)
        .instanceType(InstanceType.R5_LARGE)
        .iamAuthentication(true)
        .build();
Role role = Role.Builder.create(this, "DBRole").assumedBy(new AccountPrincipal(this.account)).build();
// Use one of the following statements to grant the role the necessary permissions
cluster.grantConnect(role); // Grant the role neptune-db:* access to the DB
cluster.grant(role, "neptune-db:ReadDataViaQuery", "neptune-db:WriteDataViaQuery");
csharp
// Install: dotnet add package Amazon.CDK.Lib
var cluster = new DatabaseCluster(this, "Cluster", new DatabaseClusterProps {
    Vpc = vpc,
    InstanceType = InstanceType.R5_LARGE,
    IamAuthentication = true
});
var role = new Role(this, "DBRole", new RoleProps { AssumedBy = new AccountPrincipal(Account) });
// Use one of the following statements to grant the role the necessary permissions
cluster.GrantConnect(role); // Grant the role neptune-db:* access to the DB
cluster.Grant(role, "neptune-db:ReadDataViaQuery", "neptune-db:WriteDataViaQuery");
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
cluster := neptune.NewDatabaseCluster(this, jsii.String("Cluster"), &DatabaseClusterProps{
	Vpc: Vpc,
	InstanceType: neptune.InstanceType_R5_LARGE(),
	IamAuthentication: jsii.Boolean(true),
})
role := iam.NewRole(this, jsii.String("DBRole"), &RoleProps{
	AssumedBy: iam.NewAccountPrincipal(this.Account),
})
// Use one of the following statements to grant the role the necessary permissions
cluster.GrantConnect(role) // Grant the role neptune-db:* access to the DB
cluster.Grant(role, jsii.String("neptune-db:ReadDataViaQuery"), jsii.String("neptune-db:WriteDataViaQuery"))

Initializer ​

ts
new AccountPrincipal(accountId: any)
python
AccountPrincipal(account_id: Any)
java
new AccountPrincipal(Object accountId)
csharp
new AccountPrincipal(object accountId)
go
NewAccountPrincipal(AccountId interface{})

Properties ​

accountIdanyaccount_idAnyaccountIdObjectAccountIdobjectAccountIdinterface{} #
AWS account ID (i.e. '123456789012').
arnstringarnstrarnStringArnstringArn*string #
Amazon Resource Name (ARN) of the principal entity (i.e. arn:aws:iam::123456789012:user/user-name).
assumeRoleActionstringassume_role_actionstrassumeRoleActionStringAssumeRoleActionstringAssumeRoleAction*string #
When this Principal is used in an AssumeRole policy, the action to use.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipal #
The principal to grant permissions to.
Return the policy fragment that identifies this principal in a Policy.
principalAccountmay be undefinedstringprincipal_accountmay be undefinedstrprincipalAccountmay be undefinedStringPrincipalAccountmay be undefinedstringPrincipalAccountmay be undefined*string #
The AWS account ID of this principal.

Can be undefined when the account is not known (for example, for service principals). Can be a Token - in that case, it's assumed to be AWS::AccountId.

Methods ​

addToAssumeRolePolicy(document: PolicyDocument): voiddef add_to_assume_role_policy(self, document: PolicyDocument) -> Nonepublic void addToAssumeRolePolicy(PolicyDocument document)public void AddToAssumeRolePolicy(PolicyDocument document)func AddToAssumeRolePolicy(Document PolicyDocument) #
Add the principal to the AssumeRolePolicyDocument.

Add the statements to the AssumeRolePolicyDocument necessary to give this principal permissions to assume the given role.

addToPolicy(statement: PolicyStatement): booleandef add_to_policy(self, statement: PolicyStatement) -> boolpublic Boolean addToPolicy(PolicyStatement statement)public bool AddToPolicy(PolicyStatement statement)func AddToPolicy(Statement PolicyStatement) *bool #
Add to the policy of this principal.
addToPrincipalPolicy(_statement: PolicyStatement): AddToPrincipalPolicyResultdef add_to_principal_policy(self, _statement: PolicyStatement) -> AddToPrincipalPolicyResultpublic AddToPrincipalPolicyResult addToPrincipalPolicy(PolicyStatement _statement)public AddToPrincipalPolicyResult AddToPrincipalPolicy(PolicyStatement _statement)func AddToPrincipalPolicy(_statement PolicyStatement) AddToPrincipalPolicyResult #
Add to the policy of this principal.
dedupeString(): stringdef dedupe_string(self, ) -> strpublic String dedupeString()public string DedupeString()func DedupeString() *string #
Return whether or not this principal is equal to the given principal.
inOrganization(organizationId: string): PrincipalBasedef in_organization(self, organization_id: str) -> PrincipalBasepublic PrincipalBase inOrganization(String organizationId)public PrincipalBase InOrganization(string organizationId)func InOrganization(OrganizationId *string) PrincipalBase #
A convenience method for adding a condition that the principal is part of the specified AWS Organization.
toJSON(): { [key: string]: string[] }def to_json(self, ) -> typing.Mapping[str, typing.List[str]]public Map<String, List<String>> toJSON()public IDictionary<string, string[]> ToJSON()func ToJSON() *map[string]*[]*string #
JSON-ify the principal.

Used when JSON.stringify() is called

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string #
Returns a string representation of an object.
withConditions(conditions: { [key: string]: any }): PrincipalBasedef with_conditions(self, conditions: typing.Mapping[str, Any]) -> PrincipalBasepublic PrincipalBase withConditions(Map<String, Object> conditions)public PrincipalBase WithConditions(IDictionary<string, object> conditions)func WithConditions(Conditions *map[string]interface{}) PrincipalBase #
Returns a new PrincipalWithConditions using this principal as the base, with the passed conditions added.

When there is a value for the same operator and key in both the principal and the conditions parameter, the value from the conditions parameter will be used.

returns

Returns: a new PrincipalWithConditions object.

withSessionTags(): PrincipalBasedef with_session_tags(self, ) -> PrincipalBasepublic PrincipalBase withSessionTags()public PrincipalBase WithSessionTags()func WithSessionTags() PrincipalBase #
Returns a new principal using this principal as the base, with session tags enabled.
returns

Returns: a new SessionTagsPrincipal object.