|
| 1 | +Description: Bedrock Access Gateway - OpenAI-compatible RESTful APIs for Amazon Bedrock |
| 2 | +Parameters: |
| 3 | + ApiKeySecretArn: |
| 4 | + Type: String |
| 5 | + AllowedPattern: ^arn:aws:secretsmanager:.*$ |
| 6 | + Description: The secret ARN in Secrets Manager used to store the API Key |
| 7 | + DefaultModelId: |
| 8 | + Type: String |
| 9 | + Default: anthropic.claude-3-sonnet-20240229-v1:0 |
| 10 | + Description: The default model ID, please make sure the model ID is supported in the current region |
| 11 | +Resources: |
| 12 | + VPCB9E5F0B4: |
| 13 | + Type: AWS::EC2::VPC |
| 14 | + Properties: |
| 15 | + CidrBlock: 10.250.0.0/16 |
| 16 | + EnableDnsHostnames: true |
| 17 | + EnableDnsSupport: true |
| 18 | + InstanceTenancy: default |
| 19 | + Tags: |
| 20 | + - Key: Name |
| 21 | + Value: BedrockProxy/VPC |
| 22 | + VPCPublicSubnet1SubnetB4246D30: |
| 23 | + Type: AWS::EC2::Subnet |
| 24 | + Properties: |
| 25 | + AvailabilityZone: |
| 26 | + Fn::Select: |
| 27 | + - 0 |
| 28 | + - Fn::GetAZs: "" |
| 29 | + CidrBlock: 10.250.0.0/24 |
| 30 | + MapPublicIpOnLaunch: true |
| 31 | + Tags: |
| 32 | + - Key: aws-cdk:subnet-name |
| 33 | + Value: Public |
| 34 | + - Key: aws-cdk:subnet-type |
| 35 | + Value: Public |
| 36 | + - Key: Name |
| 37 | + Value: BedrockProxy/VPC/PublicSubnet1 |
| 38 | + VpcId: |
| 39 | + Ref: VPCB9E5F0B4 |
| 40 | + VPCPublicSubnet1RouteTableFEE4B781: |
| 41 | + Type: AWS::EC2::RouteTable |
| 42 | + Properties: |
| 43 | + Tags: |
| 44 | + - Key: Name |
| 45 | + Value: BedrockProxy/VPC/PublicSubnet1 |
| 46 | + VpcId: |
| 47 | + Ref: VPCB9E5F0B4 |
| 48 | + VPCPublicSubnet1RouteTableAssociation0B0896DC: |
| 49 | + Type: AWS::EC2::SubnetRouteTableAssociation |
| 50 | + Properties: |
| 51 | + RouteTableId: |
| 52 | + Ref: VPCPublicSubnet1RouteTableFEE4B781 |
| 53 | + SubnetId: |
| 54 | + Ref: VPCPublicSubnet1SubnetB4246D30 |
| 55 | + VPCPublicSubnet1DefaultRoute91CEF279: |
| 56 | + Type: AWS::EC2::Route |
| 57 | + Properties: |
| 58 | + DestinationCidrBlock: 0.0.0.0/0 |
| 59 | + GatewayId: |
| 60 | + Ref: VPCIGWB7E252D3 |
| 61 | + RouteTableId: |
| 62 | + Ref: VPCPublicSubnet1RouteTableFEE4B781 |
| 63 | + DependsOn: |
| 64 | + - VPCVPCGW99B986DC |
| 65 | + VPCPublicSubnet2Subnet74179F39: |
| 66 | + Type: AWS::EC2::Subnet |
| 67 | + Properties: |
| 68 | + AvailabilityZone: |
| 69 | + Fn::Select: |
| 70 | + - 1 |
| 71 | + - Fn::GetAZs: "" |
| 72 | + CidrBlock: 10.250.1.0/24 |
| 73 | + MapPublicIpOnLaunch: true |
| 74 | + Tags: |
| 75 | + - Key: aws-cdk:subnet-name |
| 76 | + Value: Public |
| 77 | + - Key: aws-cdk:subnet-type |
| 78 | + Value: Public |
| 79 | + - Key: Name |
| 80 | + Value: BedrockProxy/VPC/PublicSubnet2 |
| 81 | + VpcId: |
| 82 | + Ref: VPCB9E5F0B4 |
| 83 | + VPCPublicSubnet2RouteTable6F1A15F1: |
| 84 | + Type: AWS::EC2::RouteTable |
| 85 | + Properties: |
| 86 | + Tags: |
| 87 | + - Key: Name |
| 88 | + Value: BedrockProxy/VPC/PublicSubnet2 |
| 89 | + VpcId: |
| 90 | + Ref: VPCB9E5F0B4 |
| 91 | + VPCPublicSubnet2RouteTableAssociation5A808732: |
| 92 | + Type: AWS::EC2::SubnetRouteTableAssociation |
| 93 | + Properties: |
| 94 | + RouteTableId: |
| 95 | + Ref: VPCPublicSubnet2RouteTable6F1A15F1 |
| 96 | + SubnetId: |
| 97 | + Ref: VPCPublicSubnet2Subnet74179F39 |
| 98 | + VPCPublicSubnet2DefaultRouteB7481BBA: |
| 99 | + Type: AWS::EC2::Route |
| 100 | + Properties: |
| 101 | + DestinationCidrBlock: 0.0.0.0/0 |
| 102 | + GatewayId: |
| 103 | + Ref: VPCIGWB7E252D3 |
| 104 | + RouteTableId: |
| 105 | + Ref: VPCPublicSubnet2RouteTable6F1A15F1 |
| 106 | + DependsOn: |
| 107 | + - VPCVPCGW99B986DC |
| 108 | + VPCIGWB7E252D3: |
| 109 | + Type: AWS::EC2::InternetGateway |
| 110 | + Properties: |
| 111 | + Tags: |
| 112 | + - Key: Name |
| 113 | + Value: BedrockProxy/VPC |
| 114 | + VPCVPCGW99B986DC: |
| 115 | + Type: AWS::EC2::VPCGatewayAttachment |
| 116 | + Properties: |
| 117 | + InternetGatewayId: |
| 118 | + Ref: VPCIGWB7E252D3 |
| 119 | + VpcId: |
| 120 | + Ref: VPCB9E5F0B4 |
| 121 | + ProxyApiHandlerServiceRoleBE71BFB1: |
| 122 | + Type: AWS::IAM::Role |
| 123 | + Properties: |
| 124 | + AssumeRolePolicyDocument: |
| 125 | + Statement: |
| 126 | + - Action: sts:AssumeRole |
| 127 | + Effect: Allow |
| 128 | + Principal: |
| 129 | + Service: lambda.amazonaws.com |
| 130 | + Version: "2012-10-17" |
| 131 | + ManagedPolicyArns: |
| 132 | + - Fn::Join: |
| 133 | + - "" |
| 134 | + - - "arn:" |
| 135 | + - Ref: AWS::Partition |
| 136 | + - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole |
| 137 | + ProxyApiHandlerServiceRoleDefaultPolicy86681202: |
| 138 | + Type: AWS::IAM::Policy |
| 139 | + Properties: |
| 140 | + PolicyDocument: |
| 141 | + Statement: |
| 142 | + - Action: |
| 143 | + - bedrock:ListFoundationModels |
| 144 | + - bedrock:ListInferenceProfiles |
| 145 | + Effect: Allow |
| 146 | + Resource: "*" |
| 147 | + - Action: |
| 148 | + - bedrock:InvokeModel |
| 149 | + - bedrock:InvokeModelWithResponseStream |
| 150 | + Effect: Allow |
| 151 | + Resource: |
| 152 | + - arn:aws:bedrock:*::foundation-model/* |
| 153 | + - arn:aws:bedrock:*:*:inference-profile/* |
| 154 | + - Action: |
| 155 | + - secretsmanager:GetSecretValue |
| 156 | + - secretsmanager:DescribeSecret |
| 157 | + Effect: Allow |
| 158 | + Resource: |
| 159 | + Ref: ApiKeySecretArn |
| 160 | + Version: "2012-10-17" |
| 161 | + PolicyName: ProxyApiHandlerServiceRoleDefaultPolicy86681202 |
| 162 | + Roles: |
| 163 | + - Ref: ProxyApiHandlerServiceRoleBE71BFB1 |
| 164 | + ProxyApiHandlerEC15A492: |
| 165 | + Type: AWS::Lambda::Function |
| 166 | + Properties: |
| 167 | + Architectures: |
| 168 | + - arm64 |
| 169 | + Code: |
| 170 | + ImageUri: |
| 171 | + Fn::Join: |
| 172 | + - "" |
| 173 | + - - 366590864501.dkr.ecr. |
| 174 | + - Ref: AWS::Region |
| 175 | + - "." |
| 176 | + - Ref: AWS::URLSuffix |
| 177 | + - /bedrock-proxy-api:latest |
| 178 | + Description: Bedrock Proxy API Handler |
| 179 | + Environment: |
| 180 | + Variables: |
| 181 | + DEBUG: "false" |
| 182 | + API_KEY_SECRET_ARN: |
| 183 | + Ref: ApiKeySecretArn |
| 184 | + DEFAULT_MODEL: |
| 185 | + Ref: DefaultModelId |
| 186 | + DEFAULT_EMBEDDING_MODEL: cohere.embed-multilingual-v3 |
| 187 | + ENABLE_CROSS_REGION_INFERENCE: "true" |
| 188 | + MemorySize: 1024 |
| 189 | + PackageType: Image |
| 190 | + Role: |
| 191 | + Fn::GetAtt: |
| 192 | + - ProxyApiHandlerServiceRoleBE71BFB1 |
| 193 | + - Arn |
| 194 | + Timeout: 600 |
| 195 | + DependsOn: |
| 196 | + - ProxyApiHandlerServiceRoleDefaultPolicy86681202 |
| 197 | + - ProxyApiHandlerServiceRoleBE71BFB1 |
| 198 | + ProxyApiHandlerInvoke2UTWxhlfyqbT5FTn5jvgbLgjFfJwzswGk55DU1HYF6C33779: |
| 199 | + Type: AWS::Lambda::Permission |
| 200 | + Properties: |
| 201 | + Action: lambda:InvokeFunction |
| 202 | + FunctionName: |
| 203 | + Fn::GetAtt: |
| 204 | + - ProxyApiHandlerEC15A492 |
| 205 | + - Arn |
| 206 | + Principal: elasticloadbalancing.amazonaws.com |
| 207 | + ProxyALB87756780: |
| 208 | + Type: AWS::ElasticLoadBalancingV2::LoadBalancer |
| 209 | + Properties: |
| 210 | + LoadBalancerAttributes: |
| 211 | + - Key: deletion_protection.enabled |
| 212 | + Value: "false" |
| 213 | + Scheme: internet-facing |
| 214 | + SecurityGroups: |
| 215 | + - Fn::GetAtt: |
| 216 | + - ProxyALBSecurityGroup0D6CA3DA |
| 217 | + - GroupId |
| 218 | + Subnets: |
| 219 | + - Ref: VPCPublicSubnet1SubnetB4246D30 |
| 220 | + - Ref: VPCPublicSubnet2Subnet74179F39 |
| 221 | + Type: application |
| 222 | + DependsOn: |
| 223 | + - VPCPublicSubnet1DefaultRoute91CEF279 |
| 224 | + - VPCPublicSubnet1RouteTableAssociation0B0896DC |
| 225 | + - VPCPublicSubnet2DefaultRouteB7481BBA |
| 226 | + - VPCPublicSubnet2RouteTableAssociation5A808732 |
| 227 | + ProxyALBSecurityGroup0D6CA3DA: |
| 228 | + Type: AWS::EC2::SecurityGroup |
| 229 | + Properties: |
| 230 | + GroupDescription: Automatically created Security Group for ELB BedrockProxyALB1CE4CAD1 |
| 231 | + SecurityGroupEgress: |
| 232 | + - CidrIp: 255.255.255.255/32 |
| 233 | + Description: Disallow all traffic |
| 234 | + FromPort: 252 |
| 235 | + IpProtocol: icmp |
| 236 | + ToPort: 86 |
| 237 | + SecurityGroupIngress: |
| 238 | + - CidrIp: 0.0.0.0/0 |
| 239 | + Description: Allow from anyone on port 80 |
| 240 | + FromPort: 80 |
| 241 | + IpProtocol: tcp |
| 242 | + ToPort: 80 |
| 243 | + VpcId: |
| 244 | + Ref: VPCB9E5F0B4 |
| 245 | + ProxyALBListener933E9515: |
| 246 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 247 | + Properties: |
| 248 | + DefaultActions: |
| 249 | + - TargetGroupArn: |
| 250 | + Ref: ProxyALBListenerTargetsGroup187739FA |
| 251 | + Type: forward |
| 252 | + LoadBalancerArn: |
| 253 | + Ref: ProxyALB87756780 |
| 254 | + Port: 80 |
| 255 | + Protocol: HTTP |
| 256 | + ProxyALBListenerTargetsGroup187739FA: |
| 257 | + Type: AWS::ElasticLoadBalancingV2::TargetGroup |
| 258 | + Properties: |
| 259 | + HealthCheckEnabled: false |
| 260 | + TargetType: lambda |
| 261 | + Targets: |
| 262 | + - Id: |
| 263 | + Fn::GetAtt: |
| 264 | + - ProxyApiHandlerEC15A492 |
| 265 | + - Arn |
| 266 | + DependsOn: |
| 267 | + - ProxyApiHandlerInvoke2UTWxhlfyqbT5FTn5jvgbLgjFfJwzswGk55DU1HYF6C33779 |
| 268 | +Outputs: |
| 269 | + APIBaseUrl: |
| 270 | + Description: Proxy API Base URL (OPENAI_API_BASE) |
| 271 | + Value: |
| 272 | + Fn::Join: |
| 273 | + - "" |
| 274 | + - - http:// |
| 275 | + - Fn::GetAtt: |
| 276 | + - ProxyALB87756780 |
| 277 | + - DNSName |
| 278 | + - /api/v1 |
| 279 | + |
0 commit comments