@@ -242,332 +242,6 @@ Resources:
242
242
name :
243
243
- !Ref UnicornInventoryBucket
244
244
245
- # #################################################
246
- # #################################################
247
- # #### demo-app (begin)
248
- # #################################################
249
- # #################################################
250
-
251
- #
252
- # Networking
253
- # VPC, 2 Public Subnets, S3/ECR/Cloudwatch Service Endpoints, Internet Gateway
254
- #
255
-
256
- StreamlitVPC :
257
- Type : AWS::EC2::VPC
258
- Properties :
259
- CidrBlock : 192.168.0.0/24
260
- EnableDnsHostnames : true
261
- EnableDnsSupport : true
262
-
263
- StreamlitSubnet1 :
264
- Type : AWS::EC2::Subnet
265
- Properties :
266
- VpcId : !Ref StreamlitVPC
267
- CidrBlock : 192.168.0.0/25
268
- AvailabilityZone : !Sub "${AWS::Region}b"
269
-
270
- StreamlitSubnet2 :
271
- Type : AWS::EC2::Subnet
272
- Properties :
273
- VpcId : !Ref StreamlitVPC
274
- CidrBlock : 192.168.0.128/25
275
- AvailabilityZone : !Sub "${AWS::Region}c"
276
-
277
- StreamlitInternetGateway :
278
- Type : AWS::EC2::InternetGateway
279
-
280
- StreamlitGatewayAttachment :
281
- Type : AWS::EC2::VPCGatewayAttachment
282
- Properties :
283
- InternetGatewayId : !Ref StreamlitInternetGateway
284
- VpcId : !Ref StreamlitVPC
285
-
286
- StreamlitSecurityGroup :
287
- Type : AWS::EC2::SecurityGroup
288
- Properties :
289
- GroupDescription : " Streamlit UI Security Group"
290
- GroupName : !Sub "${AWS::StackName}-ds-sg"
291
- SecurityGroupEgress :
292
- - IpProtocol : tcp
293
- FromPort : 0
294
- ToPort : 65535
295
- CidrIp : 0.0.0.0/0
296
- Description : Allow outbound access
297
- SecurityGroupIngress :
298
- - IpProtocol : tcp
299
- FromPort : 8501
300
- ToPort : 8501
301
- CidrIp : 0.0.0.0/0
302
- Description : Inbound only on Streamlit port
303
- VpcId : !Ref StreamlitVPC
304
-
305
- EndpointSecurityGroup :
306
- Type : AWS::EC2::SecurityGroup
307
- Properties :
308
- GroupDescription : " Streamlit UI Endpoint Security Group"
309
- GroupName : !Sub "${AWS::StackName}-ep-sg"
310
- SecurityGroupEgress :
311
- - IpProtocol : tcp
312
- FromPort : 0
313
- ToPort : 65535
314
- CidrIp : 0.0.0.0/0
315
- Description : Allow outbound access
316
- SecurityGroupIngress :
317
- - IpProtocol : tcp
318
- FromPort : 0
319
- ToPort : 65535
320
- SourceSecurityGroupId : !Ref StreamlitSecurityGroup
321
- Description : Allow inbound from Streamlit sg only
322
- VpcId : !Ref StreamlitVPC
323
-
324
- StreamlitRouteTable :
325
- Type : ' AWS::EC2::RouteTable'
326
- Properties :
327
- VpcId : !Ref StreamlitVPC
328
-
329
- InternetGatewayRoute :
330
- Type : AWS::EC2::Route
331
- Properties :
332
- GatewayId : !Ref StreamlitInternetGateway
333
- RouteTableId : !Ref StreamlitRouteTable
334
- DestinationCidrBlock : 0.0.0.0/0
335
-
336
- SubnetRouteTableAssociation1 :
337
- Type : ' AWS::EC2::SubnetRouteTableAssociation'
338
- Properties :
339
- SubnetId : !Ref StreamlitSubnet1
340
- RouteTableId : !Ref StreamlitRouteTable
341
-
342
- SubnetRouteTableAssociation2 :
343
- Type : ' AWS::EC2::SubnetRouteTableAssociation'
344
- Properties :
345
- SubnetId : !Ref StreamlitSubnet2
346
- RouteTableId : !Ref StreamlitRouteTable
347
-
348
- StreamlitVPCEndpointECRApi :
349
- Type : AWS::EC2::VPCEndpoint
350
- Properties :
351
- SecurityGroupIds :
352
- - !Ref EndpointSecurityGroup
353
- ServiceName : !Sub 'com.amazonaws.${AWS::Region}.ecr.api'
354
- SubnetIds :
355
- - !Ref StreamlitSubnet1
356
- - !Ref StreamlitSubnet2
357
- VpcEndpointType : Interface
358
- VpcId : !Ref StreamlitVPC
359
- PrivateDnsEnabled : true
360
-
361
- StreamlitVPCEndpointDocker :
362
- Type : AWS::EC2::VPCEndpoint
363
- Properties :
364
- SecurityGroupIds :
365
- - !Ref EndpointSecurityGroup
366
- ServiceName : !Sub 'com.amazonaws.${AWS::Region}.ecr.dkr'
367
- SubnetIds :
368
- - !Ref StreamlitSubnet1
369
- - !Ref StreamlitSubnet2
370
- VpcEndpointType : Interface
371
- VpcId : !Ref StreamlitVPC
372
- PrivateDnsEnabled : true
373
-
374
- StreamlitVPCEndpointLogs :
375
- Type : AWS::EC2::VPCEndpoint
376
- Properties :
377
- SecurityGroupIds :
378
- - !Ref EndpointSecurityGroup
379
- ServiceName : !Sub 'com.amazonaws.${AWS::Region}.logs'
380
- SubnetIds :
381
- - !Ref StreamlitSubnet1
382
- - !Ref StreamlitSubnet2
383
- VpcEndpointType : Interface
384
- VpcId : !Ref StreamlitVPC
385
- PrivateDnsEnabled : true
386
-
387
- StreamlitVPCEndpointS3 :
388
- Type : AWS::EC2::VPCEndpoint
389
- Properties :
390
- ServiceName : !Sub 'com.amazonaws.${AWS::Region}.s3'
391
- VpcEndpointType : Gateway
392
- VpcId : !Ref StreamlitVPC
393
- RouteTableIds :
394
- - !Ref StreamlitRouteTable
395
-
396
- LoadBalancer :
397
- Type : AWS::ElasticLoadBalancingV2::LoadBalancer
398
- Properties :
399
- Subnets :
400
- - !Ref StreamlitSubnet1
401
- - !Ref StreamlitSubnet2
402
- SecurityGroups :
403
- - !Ref StreamlitSecurityGroup
404
-
405
- LoadBalancerListener :
406
- Type : AWS::ElasticLoadBalancingV2::Listener
407
- Properties :
408
- LoadBalancerArn : !Ref LoadBalancer
409
- Port : 8501
410
- Protocol : HTTP
411
- DefaultActions :
412
- - Type : forward
413
- TargetGroupArn : !Ref TargetGroup
414
-
415
- TargetGroup :
416
- Type : AWS::ElasticLoadBalancingV2::TargetGroup
417
- Properties :
418
- Name : !Sub "${AWS::StackName}-tg-http"
419
- VpcId : !Ref StreamlitVPC
420
- Port : 8501
421
- Protocol : HTTP
422
- TargetType : ip
423
- HealthCheckEnabled : true
424
- HealthCheckIntervalSeconds : 60
425
- HealthCheckPath : " /_stcore/health"
426
- HealthCheckPort : 8501
427
- HealthCheckProtocol : HTTP
428
- TargetGroupAttributes :
429
- - Key : stickiness.enabled
430
- Value : " true"
431
- - Key : stickiness.type
432
- Value : lb_cookie
433
- - Key : stickiness.lb_cookie.duration_seconds
434
- Value : " 86500"
435
-
436
- ECSTask :
437
- Type : AWS::ECS::TaskDefinition
438
- DependsOn : LoadBalancerListener
439
- Properties :
440
- RequiresCompatibilities :
441
- - FARGATE
442
- Cpu : ' 2048'
443
- Memory : ' 4096'
444
- NetworkMode : awsvpc
445
- RuntimePlatform :
446
- CpuArchitecture : " X86_64"
447
- OperatingSystemFamily : " LINUX"
448
- ExecutionRoleArn : !Ref ExecutionRole
449
- TaskRoleArn : !Ref TaskRole
450
- ContainerDefinitions :
451
- - Name : " streamlit"
452
- Image : !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/urs-ui"
453
- MemoryReservation : 2048
454
- Cpu : 2048
455
- Memory : 4096
456
- Essential : true
457
- PortMappings :
458
- - ContainerPort : 8501
459
- Environment :
460
- - Name : BACKEND_STACK_NAME
461
- Value : !Sub "{AWS::StackName}"
462
- LogConfiguration :
463
- LogDriver : awslogs
464
- Options :
465
- awslogs-create-group : " true"
466
- awslogs-group : !Sub "/ecs/${AWS::StackName}-ECSTask"
467
- awslogs-region : !Sub "${AWS::Region}"
468
- awslogs-stream-prefix : " ecs"
469
-
470
- ECSCluster :
471
- Type : ' AWS::ECS::Cluster'
472
- Properties :
473
- ClusterName : !Sub "${AWS::StackName}-cluster"
474
-
475
- ECSService :
476
- Type : ' AWS::ECS::Service'
477
- Properties :
478
- Cluster : !Ref ECSCluster
479
- TaskDefinition : !Ref ECSTask
480
- DesiredCount : 1
481
- LaunchType : FARGATE
482
- ServiceName : !Sub "${AWS::StackName}-svc"
483
- SchedulingStrategy : " REPLICA"
484
- LoadBalancers :
485
- - ContainerName : " streamlit"
486
- ContainerPort : !Ref iECRStreamlitPort
487
- TargetGroupArn : !Ref TargetGroup
488
- HealthCheckGracePeriodSeconds : 50
489
- NetworkConfiguration :
490
- AwsvpcConfiguration :
491
- AssignPublicIp : ENABLED
492
- SecurityGroups :
493
- - !Ref StreamlitSecurityGroup
494
- Subnets :
495
- - !Ref StreamlitSubnet1
496
- - !Ref StreamlitSubnet2
497
-
498
- ExecutionRole :
499
- Type : AWS::IAM::Role
500
- Properties :
501
- RoleName : !Sub "${AWS::StackName}-execution-role"
502
- AssumeRolePolicyDocument :
503
- Statement :
504
- - Effect : Allow
505
- Principal :
506
- Service :
507
- - ecs.amazonaws.com
508
- - ecs-tasks.amazonaws.com
509
- Action : ' sts:AssumeRole'
510
- Policies :
511
- - PolicyName : cw
512
- PolicyDocument :
513
- Version : " 2012-10-17"
514
- Statement :
515
- - Effect : Allow
516
- Action :
517
- - logs:CreateLogGroup
518
- - logs:CreateLogStream
519
- - logs:PutLogEvents
520
- Resource : ' *'
521
- - PolicyName : s3-read-access-policy
522
- PolicyDocument :
523
- Version : " 2012-10-17"
524
- Statement :
525
- - Effect : Allow
526
- Action :
527
- - s3:GetObject
528
- - s3:ListBucket
529
- - s3:GetBucketLocation
530
- - s3:GetObjectVersion
531
- - s3:GetLifecycleConfiguration
532
- - s3:PutObject
533
- Resource :
534
- - !Sub " arn:aws:s3:::unicorn-inv-${AWS::StackName}-${AWS::AccountId}"
535
- - !Sub " arn:aws:s3:::unicorn-inv-${AWS::StackName}-${AWS::AccountId}/*"
536
- - PolicyName : ecr_access_policy
537
- PolicyDocument :
538
- Version : " 2012-10-17"
539
- Statement :
540
- - Effect : Allow
541
- Action :
542
- - ecr:GetAuthorizationToken
543
- - ecr:BatchCheckLayerAvailability
544
- - ecr:GetDownloadUrlForLayer
545
- - ecr:BatchGetImage
546
- Resource : " *"
547
- - PolicyName : stack_describe_for_config
548
- PolicyDocument :
549
- Version : " 2012-10-17"
550
- Statement :
551
- - Effect : Allow
552
- Action :
553
- - cloudformation:DescribeStacks
554
- Resource :
555
- - !Sub " arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}"
556
- - !Sub " arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}"
557
- TaskRole :
558
- Type : AWS::IAM::Role
559
- Properties :
560
- RoleName : !Sub "${AWS::StackName}-task-role"
561
- AssumeRolePolicyDocument :
562
- Statement :
563
- - Effect : Allow
564
- Principal :
565
- Service : ecs-tasks.amazonaws.com
566
- Action : ' sts:AssumeRole'
567
-
568
-
569
-
570
-
571
245
Outputs :
572
246
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
573
247
# Find out more about other implicit resources you can reference within SAM
@@ -587,6 +261,3 @@ Outputs:
587
261
GetFileValidatorARN :
588
262
Description : " ARN of the Lambda function required in the 'OPTIONAL: Invoke a Lambda function in the cloud' section."
589
263
Value : !GetAtt FileValidator.Arn
590
- oUiDnsName :
591
- Description : Host UI web link name
592
- Value : !Sub "http://${LoadBalancer.DNSName}:${iECRStreamlitPort}"
0 commit comments