A Smaller Bedrock Gateway, Part 6: Gateway Stack: The Front Door and Permissions
The gateway stack in readable YAML, part 2 of 3: the internal load balancer, private DNS, log groups, and IAM roles.
Series: A Smaller Bedrock Gateway (8 articles)
- …
- 6A Smaller Bedrock Gateway, Part 6: Gateway Stack: The Front Door and Permissions This article
Last updated: 2026-11-13 (Fri) 18:22 GST
In Part 5, I covered the gateway stack's inputs, secrets, and data tier. In this part, I will cover how requests get in and what the tasks are allowed to do once they are running: the internal load balancer, the private DNS name, the log groups, and the three IAM roles.
An internal load balancer that only forwards what it must
The Application Load Balancer is internal, so it has no public address. It listens only on HTTPS port 443 with the
ELBSecurityPolicy-TLS13-1-2-2021-06 policy, drops invalid header fields, and uses the strictest desync mitigation. Its default action answers every request with a fixed 403 and {"error":"path not exposed"} . Three listener rules then forward exactly three groups of paths to the tasks:-
/key/generate,/key/delete, and/v2/key/info, but only from the administrator range.
-
/v1/chat/completionsfrom the client and administrator ranges.
-
/health/livelinessand/health/readinessfrom the same two ranges.
Everything else LiteLLM serves, including its admin user interface, is unreachable through the load balancer. LiteLLM's own key check still applies to every forwarded request; the path rules reduce what can be reached, not who is trusted. The stack also adds the gateway's alias record to the private hosted zone from Part 2.
Load balancer, listener rules, and private DNS record
This block holds the load balancer, the target group, the HTTPS listener, the three rules, and the alias record. Save this block as
gateway-06.yaml . LoadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Type: application Scheme: internal IpAddressType: ipv4 Subnets: Fn::Split: - ',' - Fn::ImportValue: Fn::Sub: '${NetworkStackName}-PrivateSubnetIds' SecurityGroups: - Fn::ImportValue: Fn::Sub: '${NetworkStackName}-AlbSecurityGroupId' LoadBalancerAttributes: - Key: deletion_protection.enabled Value: !If [IsAlbDeletionProtected, 'true', 'false'] - Key: access_logs.s3.enabled Value: 'true' - Key: access_logs.s3.bucket Value: Fn::ImportValue: Fn::Sub: '${NetworkStackName}-AlbAccessLogBucketName' - Key: access_logs.s3.prefix Value: !Sub '${AWS::StackName}/alb' - Key: routing.http.drop_invalid_header_fields.enabled Value: 'true' - Key: routing.http.desync_mitigation_mode Value: strictest - Key: routing.http.preserve_host_header.enabled Value: 'true' - Key: routing.http2.enabled Value: 'true' - Key: idle_timeout.timeout_seconds Value: '300' Tags: - Key: Name Value: !Sub '${AWS::StackName}-internal' - Key: Workload Value: litellm
TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: VpcId: Fn::ImportValue: Fn::Sub: '${NetworkStackName}-VpcId' Protocol: HTTP ProtocolVersion: HTTP1 Port: 4000 TargetType: ip HealthCheckEnabled: true HealthCheckPath: /health/readiness HealthCheckPort: traffic-port HealthCheckProtocol: HTTP HealthCheckIntervalSeconds: 30 HealthCheckTimeoutSeconds: 10 HealthyThresholdCount: 2 UnhealthyThresholdCount: 3 Matcher: HttpCode: '200' TargetGroupAttributes: - Key: deregistration_delay.timeout_seconds Value: '120' - Key: load_balancing.algorithm.type Value: least_outstanding_requests - Key: stickiness.enabled Value: 'false' Tags: - Key: Name Value: !Sub '${AWS::StackName}-litellm'
HttpsListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: LoadBalancerArn: !Ref LoadBalancer Protocol: HTTPS Port: 443 SslPolicy: ELBSecurityPolicy-TLS13-1-2-2021-06 Certificates: - CertificateArn: !Ref CertificateArn DefaultActions: - Type: fixed-response FixedResponseConfig: ContentType: application/json MessageBody: '{"error":"path not exposed"}' StatusCode: '403'
AdminKeyPathAllowRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: ListenerArn: !Ref HttpsListener Priority: 10 Conditions: - Field: path-pattern PathPatternConfig: Values: - /key/generate - /key/delete - /v2/key/info - Field: source-ip SourceIpConfig: Values: - !Ref AdminIngressCidr Actions: - Type: forward TargetGroupArn: !Ref TargetGroup
ClientGenerationPathAllowRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: ListenerArn: !Ref HttpsListener Priority: 100 Conditions: - Field: path-pattern PathPatternConfig: Values: - /v1/chat/completions - Field: source-ip SourceIpConfig: Values: - !Ref ClientIngressCidr - !Ref AdminIngressCidr Actions: - Type: forward TargetGroupArn: !Ref TargetGroup
ClientHealthPathAllowRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: ListenerArn: !Ref HttpsListener Priority: 120 Conditions: - Field: path-pattern PathPatternConfig: Values: - /health/liveliness - /health/readiness - Field: source-ip SourceIpConfig: Values: - !Ref ClientIngressCidr - !Ref AdminIngressCidr Actions: - Type: forward TargetGroupArn: !Ref TargetGroup
GatewayAliasRecord: Type: AWS::Route53::RecordSet Properties: HostedZoneId: Fn::ImportValue: Fn::Sub: '${NetworkStackName}-HostedZoneId' # Orchestration verifies that this supplied name belongs to HostedZoneId; # importing a mutable private-zone name only to assert membership is avoided. Name: !Ref GatewayDomainName Type: A AliasTarget: DNSName: !GetAtt LoadBalancer.DNSName HostedZoneId: !GetAtt LoadBalancer.CanonicalHostedZoneID EvaluateTargetHealth: true
# --------------------------------------------------------------------------- # KMS-encrypted operational logs. CloudFormation generates retained log-group # names, avoiding fixed-name replacement collisions. The paired v2 network # stack's Logs endpoint policy must admit the ECS group ARN before migration; # Valkey log delivery is service-side. The KMS key permits Regional CloudWatch # Logs encryption for same-account log-group contexts. # ---------------------------------------------------------------------------Log groups
The gateway's container logs, the Valkey slow log, and the Valkey engine log each get their own log group, encrypted with the stack's KMS key and kept for the retention period you set. CloudFormation generates the names, which avoids collisions when you replace a stack.
Log groups
This block holds the three log groups. Save this block as
gateway-07.yaml . LogGroup: Type: AWS::Logs::LogGroup DeletionPolicy: Retain UpdateReplacePolicy: Retain Properties: RetentionInDays: !Ref LogRetentionDays KmsKeyId: !GetAtt GatewayKmsKey.Arn Tags: - Key: Workload Value: litellm
ValkeySlowLogGroup: Type: AWS::Logs::LogGroup DeletionPolicy: Retain UpdateReplacePolicy: Retain Properties: RetentionInDays: !Ref LogRetentionDays KmsKeyId: !GetAtt GatewayKmsKey.Arn Tags: - Key: Workload Value: litellm - Key: LogType Value: valkey-slow-log
ValkeyEngineLogGroup: Type: AWS::Logs::LogGroup DeletionPolicy: Retain UpdateReplacePolicy: Retain Properties: RetentionInDays: !Ref LogRetentionDays KmsKeyId: !GetAtt GatewayKmsKey.Arn Tags: - Key: Workload Value: litellm - Key: LogType Value: valkey-engine-log
# --------------------------------------------------------------------------- # Execution identities. Image pulls are scoped to the one repository derived # from ContainerImage. The execution role can retrieve both database and Valkey # application slots so an ECS circuit-breaker rollback can still launch the # previous task revision; each runtime container receives only the selected # slots. Migration can read only the RDS-managed administrator secret and both # database application slots; it receives no Valkey credential. # ---------------------------------------------------------------------------Execution roles: what ECS may do on the tasks' behalf
ECS uses an execution role to pull the image, write logs, and inject secrets before a container starts. There are two, so that each task gets only what it needs. Both can pull only from the one repository named in
ContainerImage and can decrypt secrets only through Secrets Manager. The runtime execution role can read both application slots for the database and Valkey, so that a deployment circuit-breaker rollback can still start the previous task revision. The migration execution role can read the RDS-managed administrator secret and the two database slots, and receives no Valkey credential at all.Execution roles
This block holds the runtime and migration execution roles. Save this block as
gateway-08.yaml . RuntimeExecutionRole: Type: AWS::IAM::Role Properties: PermissionsBoundary: !If - HasPermissionsBoundary - !Ref PermissionsBoundaryArn - !Ref 'AWS::NoValue' AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Sid: AllowEcsTasks Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: 'sts:AssumeRole' Condition: ArnLike: 'aws:SourceArn': !Sub 'arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:*' StringEquals: 'aws:SourceAccount': !Ref AWS::AccountId Policies: - PolicyName: runtime-image-logs-and-secrets PolicyDocument: Version: '2012-10-17' Statement: - Sid: GetEcrAuthorizationToken Effect: Allow Action: 'ecr:GetAuthorizationToken' Resource: '*' - Sid: PullOnlyConfiguredImageRepository Effect: Allow Action: - 'ecr:BatchCheckLayerAvailability' - 'ecr:GetDownloadUrlForLayer' - 'ecr:BatchGetImage' Resource: Fn::Sub: - 'arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/${RepositoryName}' - RepositoryName: Fn::Select: - 0 - Fn::Split: - '@' - Fn::Select: - 1 - Fn::Split: - '/' - !Ref ContainerImage - Sid: WriteGatewayLogs Effect: Allow Action: - 'logs:CreateLogStream' - 'logs:PutLogEvents' Resource: !GetAtt LogGroup.Arn - Sid: ReadRuntimeSecrets Effect: Allow Action: - 'secretsmanager:GetSecretValue' # pragma: allowlist secret - 'secretsmanager:DescribeSecret' # pragma: allowlist secret Resource: - !Ref AdministratorKeySecret - !Ref SaltKeySecret - !Ref AppDbSecretA - !Ref AppDbSecretB - !Ref ValkeyCredentialSecretA - !Ref ValkeyCredentialSecretB - Sid: DecryptRuntimeSecretsThroughSecretsManager Effect: Allow Action: 'kms:Decrypt' Resource: !GetAtt GatewayKmsKey.Arn Condition: StringEquals: 'kms:ViaService': !Sub 'secretsmanager.${AWS::Region}.${AWS::URLSuffix}' Tags: - Key: Workload Value: litellm-runtime
MigrationExecutionRole: Type: AWS::IAM::Role Properties: PermissionsBoundary: !If - HasPermissionsBoundary - !Ref PermissionsBoundaryArn - !Ref 'AWS::NoValue' AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Sid: AllowEcsTasks Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: 'sts:AssumeRole' Condition: ArnLike: 'aws:SourceArn': !Sub 'arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:*' StringEquals: 'aws:SourceAccount': !Ref AWS::AccountId Policies: - PolicyName: migration-image-logs-and-secrets PolicyDocument: Version: '2012-10-17' Statement: - Sid: GetEcrAuthorizationToken Effect: Allow Action: 'ecr:GetAuthorizationToken' Resource: '*' - Sid: PullOnlyConfiguredImageRepository Effect: Allow Action: - 'ecr:BatchCheckLayerAvailability' - 'ecr:GetDownloadUrlForLayer' - 'ecr:BatchGetImage' Resource: Fn::Sub: - 'arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/${RepositoryName}' - RepositoryName: Fn::Select: - 0 - Fn::Split: - '@' - Fn::Select: - 1 - Fn::Split: - '/' - !Ref ContainerImage - Sid: WriteMigrationLogs Effect: Allow Action: - 'logs:CreateLogStream' - 'logs:PutLogEvents' Resource: !GetAtt LogGroup.Arn - Sid: ReadMigrationDatabaseSecrets Effect: Allow Action: - 'secretsmanager:GetSecretValue' # pragma: allowlist secret - 'secretsmanager:DescribeSecret' # pragma: allowlist secret Resource: - !GetAtt Database.MasterUserSecret.SecretArn - !Ref AppDbSecretA - !Ref AppDbSecretB - Sid: DecryptMigrationSecretsThroughSecretsManager Effect: Allow Action: 'kms:Decrypt' Resource: !GetAtt GatewayKmsKey.Arn Condition: StringEquals: 'kms:ViaService': !Sub 'secretsmanager.${AWS::Region}.${AWS::URLSuffix}' Tags: - Key: Workload Value: litellm-migrationThe runtime task role: the real Bedrock boundary
The task role is what the running gateway uses to call Bedrock, and it is the primary authorization boundary. The VPC endpoint policy from Part 3 is defense in depth. The role allows invoking exactly one inference profile, allows the foundation model only through that profile and only through the dedicated VPC, and explicitly denies every Bedrock action in any Region outside the six AWS Europe geography Regions. The migration task gets no task role, so it cannot call Bedrock at all.
Runtime task role
This block holds the runtime task role. Save this block as
gateway-09.yaml . # Runtime task identity IAM is the primary Bedrock authorization boundary. The # imported network stack's Bedrock VPC endpoint policy is defense in depth and # must not be treated as a substitute for these exact profile/model grants. RuntimeTaskRole: Type: AWS::IAM::Role Properties: PermissionsBoundary: !If - HasPermissionsBoundary - !Ref PermissionsBoundaryArn - !Ref 'AWS::NoValue' AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Sid: AllowEcsTasks Effect: Allow Principal: Service: ecs-tasks.amazonaws.com Action: 'sts:AssumeRole' Condition: ArnLike: 'aws:SourceArn': !Sub 'arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:*' StringEquals: 'aws:SourceAccount': !Ref AWS::AccountId Policies: - PolicyName: exact-bedrock-model-through-dedicated-vpc PolicyDocument: Version: '2012-10-17' Statement: - Sid: InvokeExactInferenceProfile Effect: Allow Action: - 'bedrock:InvokeModel' - 'bedrock:InvokeModelWithResponseStream' Resource: !Sub 'arn:${AWS::Partition}:bedrock:eu-central-1:${AWS::AccountId}:inference-profile/${ModelId}' Condition: StringEquals: 'aws:SourceVpc': Fn::ImportValue: Fn::Sub: '${NetworkStackName}-VpcId' - Sid: InvokeExactFoundationModelThroughExactProfile Effect: Allow 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:SourceVpc': Fn::ImportValue: Fn::Sub: '${NetworkStackName}-VpcId' 'bedrock:InferenceProfileArn': !Sub 'arn:${AWS::Partition}:bedrock:eu-central-1:${AWS::AccountId}:inference-profile/${ModelId}' - Sid: DenyBedrockOutsideExactInferenceRegions Effect: Deny Action: 'bedrock:*' Resource: '*' Condition: StringNotEquals: 'aws:RequestedRegion': - eu-central-1 - eu-north-1 - eu-south-1 - eu-south-2 - eu-west-1 - eu-west-3 Tags: - Key: Workload Value: litellm-runtime
# --------------------------------------------------------------------------- # Cluster, one-shot migration/bootstrap task, and runtime task # ---------------------------------------------------------------------------A quick recap of activities
In this part, we saved the second third of the gateway template:
- An internal, TLS 1.2 and 1.3 load balancer that denies by default and forwards three path groups by source range.
- A private DNS record for the gateway.
- Three encrypted log groups.
- Two execution roles scoped to one repository and the exact secrets each task needs.
- A runtime task role that allows one inference profile through the dedicated VPC and denies Bedrock outside the six Europe Regions.
Conclusion
Requests now have a controlled way in, and each task has only the permissions it needs. In Part 7, I will add the tasks themselves, the service that runs them, and the alarms that tell you when something is wrong. That completes the template.
This is Part 6 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)
- …
- 6A Smaller Bedrock Gateway, Part 6: Gateway Stack: The Front Door and Permissions 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