src/config/policies/declarative-policies/ contains the declarative policies that set a service's account-level configuration across your AWS Organization. Unlike an SCP, which allows or denies API calls, a declarative policy sets the configuration itself, and AWS enforces it in the service for every account and Region the policy covers (declarative policies). The landing zone ships one, attached by default. You can use it as-is, modify its content, or add your own.
Declarative policies attach in organization-structure.ts through the same policies array as SCPs and tag policies. AWS Organizations allows at most 10 directly attached declarative policies per root, OU, or account, counted separately from other policy types.
Shipped declarative policy
The policy lives in ec2-guardrails.ts.
| Policy | Attached to | Intent |
|---|---|---|
blockPublicEc2SharingDeclarativePolicy (BlockPublicEc2Sharing) | Root | Blocks public sharing of EBS snapshots and AMIs in every account and Region |
It sets two EC2 attributes:
| Attribute | State | Effect |
|---|---|---|
| EBS snapshot block public access | block_all_sharing | Blocks all public sharing of snapshots. Snapshots that were already public are treated as private |
| AMI block public access | block_new_sharing | Blocks new public sharing of AMIs. AMIs that were already public stay public |
The snapshot setting also makes already-public snapshots private, which Security Hub control EC2.182 checks for. AWS supports only block_new_sharing for AMIs (EC2 policy syntax), so unshare an AMI that is already public yourself.
Example
export const blockPublicEc2SharingDeclarativePolicy: OrganizationPolicy = {
policyName: 'BlockPublicEc2Sharing',
policyType: PolicyType.DECLARATIVE_POLICY_EC2,
description: 'Blocks public sharing of EBS snapshots and AMIs',
content: {
ec2_attributes: {
snapshot_block_public_access: { state: { '@@assign': 'block_all_sharing' } },
image_block_public_access: { state: { '@@assign': 'block_new_sharing' } },
},
},
};
Adding a declarative policy
- Create a policy file in
src/config/policies/declarative-policies/and export anOrganizationPolicywithpolicyType: PolicyType.DECLARATIVE_POLICY_EC2. Writecontentin the EC2 policy syntax. - Export it from
src/config/policies/declarative-policies/index.ts. - Import it in
organization-structure.tsand add it to thepoliciesarray of the root, OU, or account that should receive it. - Run
pnpm run organization:diffto preview the change, then deploy the organization phase.
Things to know
- Member accounts can't change the setting while the policy applies. Account administrators can't modify an attribute a declarative policy manages (EC2 policy syntax).
- Detaching the policy restores the earlier setting. AWS rolls each account's attribute back to its state before the policy attached (declarative policies).
- It needs EC2 trusted access and the
DECLARATIVE_POLICY_EC2policy type. Both are on by default. KeepTrustedAccessAwsService.EC2in Trusted Access and the type enabled in Organization Policy Types. - VPC Block Public Access is not set. It cuts internet access for every VPC without an exclusion, so the landing zone leaves it off. Add it only after reviewing your workloads.
- EBS snapshot sharing is governed here only. The secure-defaults baseline doesn't set it; see SecureDefaultsConstruct.