PolicyStatementProps Struct
Interface for creating a policy statement.
| Source | aws-iam/lib/policy-statement.ts |
|---|
Example
ts
// Add gateway endpoints when creating the VPC
const vpc = new ec2.Vpc(this, 'MyVpc', {
gatewayEndpoints: {
S3: {
service: ec2.GatewayVpcEndpointAwsService.S3,
},
},
});
// Alternatively gateway endpoints can be added on the VPC
const dynamoDbEndpoint = vpc.addGatewayEndpoint('DynamoDbEndpoint', {
service: ec2.GatewayVpcEndpointAwsService.DYNAMODB,
});
// This allows to customize the endpoint policy
dynamoDbEndpoint.addToPolicy(
new iam.PolicyStatement({ // Restrict to listing and describing tables
principals: [new iam.AnyPrincipal()],
actions: ['dynamodb:DescribeTable', 'dynamodb:ListTables'],
resources: ['*'],
}));
// Add an interface endpoint
vpc.addInterfaceEndpoint('EcrDockerEndpoint', {
service: ec2.InterfaceVpcEndpointAwsService.ECR_DOCKER,
// Uncomment the following to allow more fine-grained control over
// who can access the endpoint via the '.connections' object.
// open: false
});
python
# Add gateway endpoints when creating the VPC
vpc = ec2.Vpc(self, "MyVpc",
gateway_endpoints={
"S3": cdk.aws_ec2.GatewayVpcEndpointOptions(
service=ec2.GatewayVpcEndpointAwsService.S3
)
}
)
# Alternatively gateway endpoints can be added on the VPC
dynamo_db_endpoint = vpc.add_gateway_endpoint("DynamoDbEndpoint",
service=ec2.GatewayVpcEndpointAwsService.DYNAMODB
)
# This allows to customize the endpoint policy
dynamo_db_endpoint.add_to_policy(
iam.PolicyStatement( # Restrict to listing and describing tables
principals=[iam.AnyPrincipal()],
actions=["dynamodb:DescribeTable", "dynamodb:ListTables"],
resources=["*"]))
# Add an interface endpoint
vpc.add_interface_endpoint("EcrDockerEndpoint",
service=ec2.InterfaceVpcEndpointAwsService.ECR_DOCKER
)
java
// Add gateway endpoints when creating the VPC
Vpc vpc = Vpc.Builder.create(this, "MyVpc")
.gatewayEndpoints(Map.of(
"S3", GatewayVpcEndpointOptions.builder()
.service(GatewayVpcEndpointAwsService.S3)
.build()))
.build();
// Alternatively gateway endpoints can be added on the VPC
GatewayVpcEndpoint dynamoDbEndpoint = vpc.addGatewayEndpoint("DynamoDbEndpoint", GatewayVpcEndpointOptions.builder()
.service(GatewayVpcEndpointAwsService.DYNAMODB)
.build());
// This allows to customize the endpoint policy
dynamoDbEndpoint.addToPolicy(
PolicyStatement.Builder.create() // Restrict to listing and describing tables
.principals(List.of(new AnyPrincipal()))
.actions(List.of("dynamodb:DescribeTable", "dynamodb:ListTables"))
.resources(List.of("*")).build());
// Add an interface endpoint
vpc.addInterfaceEndpoint("EcrDockerEndpoint", InterfaceVpcEndpointOptions.builder()
.service(InterfaceVpcEndpointAwsService.ECR_DOCKER)
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Add gateway endpoints when creating the VPC
var vpc = new Vpc(this, "MyVpc", new VpcProps {
GatewayEndpoints = new Dictionary<string, GatewayVpcEndpointOptions> {
{ "S3", new GatewayVpcEndpointOptions {
Service = GatewayVpcEndpointAwsService.S3
} }
}
});
// Alternatively gateway endpoints can be added on the VPC
var dynamoDbEndpoint = vpc.AddGatewayEndpoint("DynamoDbEndpoint", new GatewayVpcEndpointOptions {
Service = GatewayVpcEndpointAwsService.DYNAMODB
});
// This allows to customize the endpoint policy
dynamoDbEndpoint.AddToPolicy(
new PolicyStatement(new PolicyStatementProps { // Restrict to listing and describing tables
Principals = new [] { new AnyPrincipal() },
Actions = new [] { "dynamodb:DescribeTable", "dynamodb:ListTables" },
Resources = new [] { "*" } }));
// Add an interface endpoint
vpc.AddInterfaceEndpoint("EcrDockerEndpoint", new InterfaceVpcEndpointOptions {
Service = InterfaceVpcEndpointAwsService.ECR_DOCKER
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Add gateway endpoints when creating the VPC
vpc := ec2.NewVpc(this, jsii.String("MyVpc"), &VpcProps{
GatewayEndpoints: map[string]GatewayVpcEndpointOptions{
"S3": &GatewayVpcEndpointOptions{
"service": ec2.GatewayVpcEndpointAwsService_S3(),
},
},
})
// Alternatively gateway endpoints can be added on the VPC
dynamoDbEndpoint := vpc.addGatewayEndpoint(jsii.String("DynamoDbEndpoint"), &GatewayVpcEndpointOptions{
Service: ec2.GatewayVpcEndpointAwsService_DYNAMODB(),
})
// This allows to customize the endpoint policy
dynamoDbEndpoint.AddToPolicy(
iam.NewPolicyStatement(&PolicyStatementProps{
// Restrict to listing and describing tables
Principals: []IPrincipal{
iam.NewAnyPrincipal(),
},
Actions: []*string{
jsii.String("dynamodb:DescribeTable"),
jsii.String("dynamodb:ListTables"),
},
Resources: []*string{
jsii.String("*"),
},
}))
// Add an interface endpoint
vpc.addInterfaceEndpoint(jsii.String("EcrDockerEndpoint"), &InterfaceVpcEndpointOptions{
Service: ec2.InterfaceVpcEndpointAwsService_ECR_DOCKER(),
})
Properties
actionsoptionalstring[]actionsoptionaltyping.List[str]actionsoptionalList<String>Actionsoptionalstring[]Actionsoptional*[]*string #List of actions to add to the statement.
Default: no actions
conditionsoptional{ [key: string]: any }conditionsoptionaltyping.Mapping[str, Any]conditionsoptionalMap<String, Object>ConditionsoptionalIDictionary<string, object>Conditionsoptional*map[string]interface{} #Conditions to add to the statement.
Default: no condition
effectoptionalEffecteffectoptionalEffecteffectoptionalEffectEffectoptionalEffectEffectoptionalEffect = Effect.ALLOW #Whether to allow or deny the actions in this statement.
notActionsoptionalstring[]not_actionsoptionaltyping.List[str]notActionsoptionalList<String>NotActionsoptionalstring[]NotActionsoptional*[]*string #List of not actions to add to the statement.
Default: no not-actions
notPrincipalsoptionalIPrincipal[]not_principalsoptionaltyping.List[IPrincipal]notPrincipalsoptionalList<IPrincipal>NotPrincipalsoptionalIPrincipal[]NotPrincipalsoptional*[]IPrincipal #List of not principals to add to the statement.
Default: no not principals
notResourcesoptionalstring[]not_resourcesoptionaltyping.List[str]notResourcesoptionalList<String>NotResourcesoptionalstring[]NotResourcesoptional*[]*string #NotResource ARNs to add to the statement.
Default: no not-resources
principalsoptionalIPrincipal[]principalsoptionaltyping.List[IPrincipal]principalsoptionalList<IPrincipal>PrincipalsoptionalIPrincipal[]Principalsoptional*[]IPrincipal #List of principals to add to the statement.
Default: no principals
resourcesoptionalstring[]resourcesoptionaltyping.List[str]resourcesoptionalList<String>Resourcesoptionalstring[]Resourcesoptional*[]*string #Resource ARNs to add to the statement.
Default: no resources
The Sid (statement ID) is an optional identifier that you provide for the policy statement.
Default: no sid
notes
You can assign a Sid value to each statement in a statement array. In services that let you specify an ID element, such as SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In IAM, the Sid value must be unique within a JSON policy. In IAM identity policies, the Sid value must contain only alphanumeric characters.