A Smaller Bedrock Gateway, Part 3: Security Groups, Private Endpoints, and Deploying the Network
Security groups and private VPC endpoints in readable YAML, then deploy the network stack and check the boundary in the console.
Series: A Smaller Bedrock Gateway (8 articles)
- …
- 3A Smaller Bedrock Gateway, Part 3: Security Groups, Private Endpoints, and Deploying the Network This article
Last updated: 2026-11-13 (Fri) 18:22 GST
In Part 2, I built a VPC with no route to the internet. In this part, I will complete the network stack with the security groups and the VPC endpoints, deploy it, and check the private boundary in the console before anything runs inside it.
A security-group graph owned by one stack
The network stack owns every security group and every rule between them. The gateway stack in Parts 5 to 7 only attaches these groups and creates no rules of its own, so the whole graph can be reviewed in one place. No group keeps the default allow-all egress. The database, cache, and endpoint groups need no outbound access, so each gets a placeholder egress rule to
127.0.0.1/32 . Every other path is an explicit rule:- Tasks can reach the endpoints and the S3 prefix list on TCP 443, PostgreSQL on TCP 5432, and Valkey on TCP 6379. Nothing else.
- The load balancer accepts TCP 443 only from the client and administrator ranges, and forwards only to the tasks on TCP 4000.
- The database, the cache, and the endpoints accept connections only from the task group.
- The validation probe used in Part 8 can reach the load balancer, the endpoints, and S3, plus one public address,
1.1.1.1on TCP 443. That rule exists so the probe can prove that a direct connection to the internet fails even when a security group would allow it.
Security groups
This block holds the six groups and the ingress rules between them. Save this block as
network-06.yaml . EndpointSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Interface endpoint ENIs reachable only from LiteLLM tasks. VpcId: !Ref Vpc SecurityGroupEgress: - IpProtocol: '-1' CidrIp: 127.0.0.1/32 Description: Suppress implicit allow-all egress; endpoint ENIs initiate no traffic. Tags: - Key: Name Value: !Sub '${AWS::StackName}-endpoints'
DatabaseSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: PostgreSQL reachable only from LiteLLM tasks. VpcId: !Ref Vpc SecurityGroupEgress: - IpProtocol: '-1' CidrIp: 127.0.0.1/32 Description: Suppress implicit allow-all egress; RDS initiates no connections. Tags: - Key: Name Value: !Sub '${AWS::StackName}-database'
CacheSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Valkey cache reachable only from LiteLLM tasks. VpcId: !Ref Vpc SecurityGroupEgress: - IpProtocol: '-1' CidrIp: 127.0.0.1/32 Description: Suppress implicit allow-all egress; cache nodes initiate no connections. Tags: - Key: Name Value: !Sub '${AWS::StackName}-cache'
TaskSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: LiteLLM migration and runtime tasks with explicit destinations only. VpcId: !Ref Vpc SecurityGroupEgress: - IpProtocol: tcp FromPort: 443 ToPort: 443 DestinationSecurityGroupId: !Ref EndpointSecurityGroup Description: HTTPS to required interface endpoints only. - IpProtocol: tcp FromPort: 443 ToPort: 443 DestinationPrefixListId: !Ref S3PrefixListId Description: HTTPS to S3 through the gateway endpoint for ECR image layers. - IpProtocol: tcp FromPort: 5432 ToPort: 5432 DestinationSecurityGroupId: !Ref DatabaseSecurityGroup Description: PostgreSQL to the LiteLLM database only. - IpProtocol: tcp FromPort: 6379 ToPort: 6379 DestinationSecurityGroupId: !Ref CacheSecurityGroup Description: Valkey to the LiteLLM cache only. Tags: - Key: Name Value: !Sub '${AWS::StackName}-tasks'
AlbSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Internal LiteLLM ALB with approved private sources only. VpcId: !Ref Vpc SecurityGroupIngress: - IpProtocol: tcp FromPort: 443 ToPort: 443 CidrIp: !Ref ClientIngressCidr Description: HTTPS from the approved private client CIDR. - IpProtocol: tcp FromPort: 443 ToPort: 443 CidrIp: !Ref AdminIngressCidr Description: HTTPS from the separate private administrator CIDR. SecurityGroupEgress: - IpProtocol: tcp FromPort: 4000 ToPort: 4000 DestinationSecurityGroupId: !Ref TaskSecurityGroup Description: HTTP to LiteLLM task targets only. Tags: - Key: Name Value: !Sub '${AWS::StackName}-alb'
ProbeSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Validation probe with only required private service egress. VpcId: !Ref Vpc SecurityGroupEgress: - IpProtocol: tcp FromPort: 443 ToPort: 443 DestinationSecurityGroupId: !Ref AlbSecurityGroup Description: HTTPS to the internal gateway ALB only. - IpProtocol: tcp FromPort: 443 ToPort: 443 DestinationSecurityGroupId: !Ref EndpointSecurityGroup Description: HTTPS to ECR, Logs, and Secrets Manager interface endpoints. - IpProtocol: tcp FromPort: 443 ToPort: 443 DestinationPrefixListId: !Ref S3PrefixListId Description: HTTPS to S3 through the gateway endpoint for ECR image layers. - IpProtocol: tcp FromPort: 443 ToPort: 443 CidrIp: 1.1.1.1/32 Description: Route-isolation negative control to one public IPv4 address. Tags: - Key: Name Value: !Sub '${AWS::StackName}-probe'
TaskIngressFromAlb: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: !Ref TaskSecurityGroup IpProtocol: tcp FromPort: 4000 ToPort: 4000 SourceSecurityGroupId: !Ref AlbSecurityGroup Description: LiteLLM port from the internal ALB only.
DatabaseIngressFromTasks: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: !Ref DatabaseSecurityGroup IpProtocol: tcp FromPort: 5432 ToPort: 5432 SourceSecurityGroupId: !Ref TaskSecurityGroup Description: PostgreSQL from LiteLLM migration and runtime tasks only.
CacheIngressFromTasks: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: !Ref CacheSecurityGroup IpProtocol: tcp FromPort: 6379 ToPort: 6379 SourceSecurityGroupId: !Ref TaskSecurityGroup Description: Valkey from LiteLLM migration and runtime tasks only.
EndpointIngressFromTasks: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: !Ref EndpointSecurityGroup IpProtocol: tcp FromPort: 443 ToPort: 443 SourceSecurityGroupId: !Ref TaskSecurityGroup Description: HTTPS from LiteLLM migration and runtime tasks only.
EndpointIngressFromProbe: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: !Ref EndpointSecurityGroup IpProtocol: tcp FromPort: 443 ToPort: 443 SourceSecurityGroupId: !Ref ProbeSecurityGroup Description: HTTPS from the validation probe for image pulls, secrets, and logs.
# --------------------------------------------------------------------------- # Five required interface endpoints and the S3 gateway endpoint # ---------------------------------------------------------------------------
# There are deliberately no STS or KMS interface endpoints. The tasks receive # role credentials from the ECS container credential provider and never call an # STS API. Secret injection calls Secrets Manager; kms:Decrypt is authorized with # kms:ViaService so Secrets Manager performs decryption on the caller's behalf. # ECR, CloudWatch Logs, RDS, and S3 encryption are likewise service-side. If the # application later calls STS or KMS directly, add that endpoint, its DNS name, # endpoint policy, and SG validation together.The Bedrock Runtime endpoint
The Bedrock Runtime interface endpoint is the only way the tasks reach the model. Its policy allows
InvokeModel and InvokeModelWithResponseStream on exactly one inference profile in this account, and on the foundation model in the six AWS Europe geography Regions only when the request comes through that profile. The comments in the template are worth reading: the endpoint policy is defense in depth, not the primary control. The runtime task role in Part 6 grants the same exact permissions and denies Bedrock outside those Regions.There are deliberately no STS or KMS endpoints. The tasks get role credentials from the ECS credential provider and never call STS, and every decryption happens inside Secrets Manager, CloudWatch Logs, ECR, RDS, or S3 on the caller's behalf.
Bedrock Runtime endpoint
This block holds the endpoint and its policy. Save this block as
network-07.yaml . # This endpoint policy is defense in depth. It permits only the reviewed profile # and its exact foundation model destinations, but it is not independent proof of # inference routing or processing location. Stack 2 must also grant the exact task # role permissions and validate the deployed behavior. BedrockRuntimeEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.bedrock-runtime' VpcEndpointType: Interface SubnetIds: - !Ref PrivateSubnetA - !Ref PrivateSubnetB SecurityGroupIds: - !Ref EndpointSecurityGroup PrivateDnsEnabled: true PolicyDocument: Version: '2012-10-17' Statement: - Sid: InvokeExactEuropeInferenceProfile Effect: Allow Principal: '*' Action: - 'bedrock:InvokeModel' - 'bedrock:InvokeModelWithResponseStream' Resource: - !Sub 'arn:${AWS::Partition}:bedrock:eu-central-1:${AWS::AccountId}:inference-profile/${ModelId}' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId - Sid: InvokeExactFoundationModelsThroughExactProfile Effect: Allow Principal: '*' Action: - 'bedrock:InvokeModel' - 'bedrock:InvokeModelWithResponseStream' Resource: - !Sub 'arn:${AWS::Partition}:bedrock:eu-central-1::foundation-model/${FoundationModelId}' - !Sub 'arn:${AWS::Partition}:bedrock:eu-north-1::foundation-model/${FoundationModelId}' - !Sub 'arn:${AWS::Partition}:bedrock:eu-south-1::foundation-model/${FoundationModelId}' - !Sub 'arn:${AWS::Partition}:bedrock:eu-south-2::foundation-model/${FoundationModelId}' - !Sub 'arn:${AWS::Partition}:bedrock:eu-west-1::foundation-model/${FoundationModelId}' - !Sub 'arn:${AWS::Partition}:bedrock:eu-west-3::foundation-model/${FoundationModelId}' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId 'bedrock:InferenceProfileArn': !Sub 'arn:${AWS::Partition}:bedrock:eu-central-1:${AWS::AccountId}:inference-profile/${ModelId}' Tags: - Key: Name Value: !Sub '${AWS::StackName}-bedrock-runtime'Endpoints for the image, the secrets, and the logs
The ECR API and ECR Docker endpoints let Fargate authenticate and pull the image manifest. The layers themselves come from S3 through the gateway endpoint. Secrets Manager injects the database, Valkey, and administrator credentials at task start, and CloudWatch Logs receives the container logs. Each endpoint policy is scoped to this account and to the actions that service needs, and the IAM roles in Part 6 narrow them further to one repository, the exact secrets, and the exact log groups.
ECR, Secrets Manager, Logs, and S3 endpoints
This block holds the remaining five endpoints. Save this block as
network-08.yaml . EcrApiEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.ecr.api' VpcEndpointType: Interface SubnetIds: - !Ref PrivateSubnetA - !Ref PrivateSubnetB SecurityGroupIds: - !Ref EndpointSecurityGroup PrivateDnsEnabled: true PolicyDocument: Version: '2012-10-17' Statement: - Sid: GetAuthorizationToken Effect: Allow Principal: '*' Action: 'ecr:GetAuthorizationToken' Resource: '*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId - Sid: PullFromSameAccountRepositories Effect: Allow Principal: '*' Action: - 'ecr:BatchCheckLayerAvailability' - 'ecr:BatchGetImage' - 'ecr:GetDownloadUrlForLayer' Resource: !Sub 'arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId Tags: - Key: Name Value: !Sub '${AWS::StackName}-ecr-api'
EcrDkrEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.ecr.dkr' VpcEndpointType: Interface SubnetIds: - !Ref PrivateSubnetA - !Ref PrivateSubnetB SecurityGroupIds: - !Ref EndpointSecurityGroup PrivateDnsEnabled: true PolicyDocument: Version: '2012-10-17' Statement: - Sid: GetAuthorizationToken Effect: Allow Principal: '*' Action: 'ecr:GetAuthorizationToken' Resource: '*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId - Sid: PullFromSameAccountRepositories Effect: Allow Principal: '*' Action: - 'ecr:BatchCheckLayerAvailability' - 'ecr:BatchGetImage' - 'ecr:GetDownloadUrlForLayer' Resource: !Sub 'arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId Tags: - Key: Name Value: !Sub '${AWS::StackName}-ecr-dkr'
SecretsManagerEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.secretsmanager' VpcEndpointType: Interface SubnetIds: - !Ref PrivateSubnetA - !Ref PrivateSubnetB SecurityGroupIds: - !Ref EndpointSecurityGroup PrivateDnsEnabled: true PolicyDocument: Version: '2012-10-17' Statement: - Sid: ReadSameAccountSecrets Effect: Allow Principal: '*' Action: - 'secretsmanager:DescribeSecret' - 'secretsmanager:GetSecretValue' Resource: !Sub 'arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId Tags: - Key: Name Value: !Sub '${AWS::StackName}-secrets-manager'
# CloudFormation generates the log-group names, so this endpoint-policy resource # accepts generated same-account log streams in this source Region and VPC. Exact # execution-role IAM permissions and endpoint security-group source restrictions # provide the identity and network controls. CloudWatchLogsEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.logs' VpcEndpointType: Interface SubnetIds: - !Ref PrivateSubnetA - !Ref PrivateSubnetB SecurityGroupIds: - !Ref EndpointSecurityGroup PrivateDnsEnabled: true PolicyDocument: Version: '2012-10-17' Statement: - Sid: PublishSameAccountLogsFromThisVpc Effect: Allow Principal: '*' Action: - 'logs:CreateLogStream' - 'logs:PutLogEvents' Resource: !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:*:log-stream:*' Condition: StringEquals: 'aws:PrincipalAccount': !Ref AWS::AccountId 'aws:SourceVpc': !Ref Vpc Tags: - Key: Name Value: !Sub '${AWS::StackName}-cloudwatch-logs'
# ECR stores image layers in this Regional S3 bucket. The policy deliberately grants # only GetObject on that bucket. Adding a principal-account condition here would break # ECR's service-signed presigned layer URLs, so the bucket ARN is the hard boundary. S3GatewayEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcId: !Ref Vpc ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3' VpcEndpointType: Gateway RouteTableIds: - !Ref PrivateRouteTableA - !Ref PrivateRouteTableB PolicyDocument: Version: '2012-10-17' Statement: - Sid: EcrLayerBucketOnly Effect: Allow Principal: '*' Action: 's3:GetObject' Resource: !Sub 'arn:${AWS::Partition}:s3:::prod-${AWS::Region}-starport-layer-bucket/*' Tags: - Key: Name Value: !Sub '${AWS::StackName}-s3'Outputs
The outputs export the VPC, subnets, security groups, prefix list, hosted zone, and log bucket so that the gateway stack can import them by name. Save this block as
network-09.yaml .Outputs:
VpcId: Description: Dedicated VPC ID for stack 2. Value: !Ref Vpc Export: Name: !Sub '${AWS::StackName}-VpcId'
VpcCidr: Description: Dedicated VPC IPv4 CIDR for external private-connectivity planning. Value: !GetAtt Vpc.CidrBlock Export: Name: !Sub '${AWS::StackName}-VpcCidr'
PrivateSubnetIds: Description: Comma-separated IDs of the two private subnets for stack 2. Value: !Join - ',' - - !Ref PrivateSubnetA - !Ref PrivateSubnetB Export: Name: !Sub '${AWS::StackName}-PrivateSubnetIds'
EndpointSecurityGroupId: Description: Interface-endpoint SG with production ingress owned entirely by this stack. Value: !Ref EndpointSecurityGroup Export: Name: !Sub '${AWS::StackName}-EndpointSecurityGroupId'
AlbSecurityGroupId: Description: Internal ALB SG with client/admin ingress and task-only egress. Value: !Ref AlbSecurityGroup Export: Name: !Sub '${AWS::StackName}-AlbSecurityGroupId'
TaskSecurityGroupId: Description: Migration/runtime task SG with endpoint, S3, database, and Valkey cache egress only. Value: !Ref TaskSecurityGroup Export: Name: !Sub '${AWS::StackName}-TaskSecurityGroupId'
DatabaseSecurityGroupId: Description: PostgreSQL SG with task-only ingress. Value: !Ref DatabaseSecurityGroup Export: Name: !Sub '${AWS::StackName}-DatabaseSecurityGroupId'
CacheSecurityGroupId: Description: Valkey cache SG with task-only ingress and synthetic egress suppression. Value: !Ref CacheSecurityGroup Export: Name: !Sub '${AWS::StackName}-CacheSecurityGroupId'
ProbeSecurityGroupId: Description: Validation-probe SG with explicit ALB, endpoint, S3, and negative-control egress. Value: !Ref ProbeSecurityGroup Export: Name: !Sub '${AWS::StackName}-ProbeSecurityGroupId'
S3PrefixListId: Description: Regional Amazon S3 managed prefix list ID for private image-layer pulls. Value: !Ref S3PrefixListId Export: Name: !Sub '${AWS::StackName}-S3PrefixListId'
HostedZoneId: Description: ID of the retained Route 53 private hosted zone. Value: !Ref PrivateHostedZone Export: Name: !Sub '${AWS::StackName}-HostedZoneId'
AlbAccessLogBucketName: Description: >- Retained SSE-S3 bucket for stack 2's Application Load Balancer access logs. Value: !Ref AlbAccessLogBucket Export: Name: !Sub '${AWS::StackName}-AlbAccessLogBucketName'Join and check the network template
Run this in the folder that holds the nine blocks. The first command joins them in order and restores the blank line between each pair. The second prints nothing if the result is exactly the validated template, and fails if it is not.
awk 'FNR==1 && NR>1 {print ""} 1' network-*.yaml > 07-01-bedrock-endpoints.yamlecho 'd46536d083851f4e97ab3f824064f9ad1e3766d87feecd27969538cd122c0037 07-01-bedrock-endpoints.yaml' | shasum -a 256 -c --quiet -Deploy the network stack
Set these variables in your shell. You will use the same shell for the rest of the series, so keep it open. Replace the values in capitals.
export AWS_REGION=eu-central-1NETWORK_STACK=bedrock-gateway-networkGATEWAY_STACK=bedrock-gatewayVPC_CIDR=10.20.0.0/16CLIENT_CIDR=10.99.0.0/16 # private range your applications connect fromADMIN_CIDR=10.20.0.0/16 # range your administrators connect from; must differ from CLIENT_CIDRCERTIFICATE_ARN=YOUR_ACM_CERTIFICATE_ARNTEMPLATE_BUCKET=YOUR_TEMPLATE_STAGING_BUCKETIMAGE_REPOSITORY=YOUR_ACCOUNT.dkr.ecr.eu-central-1.amazonaws.com/litellmout() { aws cloudformation describe-stacks --stack-name "$1" \ --query "Stacks[0].Outputs[?OutputKey=='$2'].OutputValue" --output text; }Look up the managed prefix list for S3 in the Region, then deploy the stack. It takes a few minutes.
S3_PREFIX_LIST_ID=$(aws ec2 describe-managed-prefix-lists \ --filters Name=prefix-list-name,Values=com.amazonaws.$AWS_REGION.s3 \ --query 'PrefixLists[0].PrefixListId' --output text)
aws cloudformation deploy \ --stack-name "$NETWORK_STACK" \ --template-file 07-01-bedrock-endpoints.yaml \ --capabilities CAPABILITY_IAM \ --parameter-overrides \ VpcCidr="$VPC_CIDR" \ PrivateHostedZoneName=internal.example \ GatewayStackName="$GATEWAY_STACK" \ ClientIngressCidr="$CLIENT_CIDR" \ AdminIngressCidr="$ADMIN_CIDR" \ S3PrefixListId="$S3_PREFIX_LIST_ID"Check the private boundary
Before you put anything into the VPC, check the boundary yourself. In the Amazon VPC console, choose Endpoints and filter by the new VPC. You should see five interface endpoints and one gateway endpoint for S3.

Figure 1. The five interface endpoints and the S3 gateway endpoint in the dedicated VPC.
Next, open Route tables, select one of the two private route tables, and choose the Routes tab. There should be only the local route and the S3 prefix-list route through the gateway endpoint. If you see a
0.0.0.0/0 or ::/0 route, stop and find out who added it.
Figure 2. A private route table with only the local route and the S3 gateway endpoint route.
Finally, open DNS firewall rule groups and look at the rule group the stack created. The allow rule comes first and the block-everything rule comes second.

Figure 3. The DNS Firewall rule group: allow the approved names first, then block everything else.
Confirm that DNS Firewall fails closed for this VPC. The command must print
DISABLED .VPC_ID=$(out "$NETWORK_STACK" VpcId)aws route53resolver get-firewall-config --resource-id "$VPC_ID" \ --query 'FirewallConfig.FirewallFailOpen' --output textA quick recap of activities
In this part, we:
- Added a security-group graph in which each component can reach only the components it needs.
- Added a Bedrock Runtime endpoint whose policy allows one inference profile and its six destination Regions.
- Added the ECR, Secrets Manager, Logs, and S3 endpoints, and no STS or KMS endpoints.
- Joined the nine blocks, checked the result against the validated template, and deployed the network stack.
- Checked the endpoints, routes, DNS rules, and fail-closed setting in the console.
Conclusion
The network is now in place and you have seen for yourself that it has no way out. In Part 4, I will build the hardened LiteLLM image that the gateway runs, before we deploy the gateway stack itself.
This is Part 3 of the eight-part A Smaller Bedrock Gateway series. Part 1 covers the design, Parts 2 and 3 the network stack, Part 4 the hardened image, Parts 5 to 7 the gateway stack, and Part 8 the deployment, validation, and day-two operations.
Series: A Smaller Bedrock Gateway (8 articles)
- …
- 3A Smaller Bedrock Gateway, Part 3: Security Groups, Private Endpoints, and Deploying the Network This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article