Skip to content

Commit 080690c

Browse files
committed
Adding permissions for ECS task
1 parent 954436c commit 080690c

File tree

1 file changed

+56
-17
lines changed

1 file changed

+56
-17
lines changed

workshops/serverless-testing-workshop/template.yaml

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ Resources:
296296
Description: Allow outbound access
297297
SecurityGroupIngress:
298298
- IpProtocol: tcp
299-
FromPort: !Ref iECRStreamlitPort
300-
ToPort: !Ref iECRStreamlitPort
299+
FromPort: 8501
300+
ToPort: 8501
301301
CidrIp: 0.0.0.0/0
302302
Description: Inbound only on Streamlit port
303303
VpcId: !Ref StreamlitVPC
@@ -406,7 +406,7 @@ Resources:
406406
Type: AWS::ElasticLoadBalancingV2::Listener
407407
Properties:
408408
LoadBalancerArn: !Ref LoadBalancer
409-
Port: !Ref iECRStreamlitPort
409+
Port: 8501
410410
Protocol: HTTP
411411
DefaultActions:
412412
- Type: forward
@@ -417,13 +417,13 @@ Resources:
417417
Properties:
418418
Name: !Sub "${AWS::StackName}-tg-http"
419419
VpcId: !Ref StreamlitVPC
420-
Port: !Ref iECRStreamlitPort
420+
Port: 8501
421421
Protocol: HTTP
422422
TargetType: ip
423423
HealthCheckEnabled: true
424424
HealthCheckIntervalSeconds: 60
425425
HealthCheckPath: "/_stcore/health"
426-
HealthCheckPort: !Ref iECRStreamlitPort
426+
HealthCheckPort: 8501
427427
HealthCheckProtocol: HTTP
428428
TargetGroupAttributes:
429429
- Key: stickiness.enabled
@@ -449,13 +449,16 @@ Resources:
449449
TaskRoleArn: !Ref TaskRole
450450
ContainerDefinitions:
451451
- Name: "streamlit"
452-
Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/docsearch-ecr"
452+
Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/urs-ui"
453453
MemoryReservation: 2048
454454
Cpu: 2048
455455
Memory: 4096
456456
Essential: true
457457
PortMappings:
458-
- ContainerPort: !Ref iECRStreamlitPort
458+
- ContainerPort: 8501
459+
Environment:
460+
- Name: BACKEND_STACK_NAME
461+
Value: !Sub "{AWS::StackName}"
459462
LogConfiguration:
460463
LogDriver: awslogs
461464
Options:
@@ -500,24 +503,57 @@ Resources:
500503
Statement:
501504
- Effect: Allow
502505
Principal:
503-
Service: ecs-tasks.amazonaws.com
506+
Service:
507+
- ecs.amazonaws.com
508+
- ecs-tasks.amazonaws.com
504509
Action: 'sts:AssumeRole'
505510
Policies:
506-
- PolicyName: root
511+
- PolicyName: cw
507512
PolicyDocument:
508513
Version: "2012-10-17"
509514
Statement:
510515
- Effect: Allow
511516
Action:
512-
- "ecr:GetAuthorizationToken"
513-
- "ecr:BatchCheckLayerAvailability"
514-
- "ecr:GetDownloadUrlForLayer"
515-
- "ecr:BatchGetImage"
516-
- "logs:CreateLogStream"
517-
- "logs:PutLogEvents"
518-
- "logs:CreateLogGroup"
517+
- logs:CreateLogGroup
518+
- logs:CreateLogStream
519+
- logs:PutLogEvents
519520
Resource: '*'
520-
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}"
521557
TaskRole:
522558
Type: AWS::IAM::Role
523559
Properties:
@@ -529,6 +565,9 @@ Resources:
529565
Service: ecs-tasks.amazonaws.com
530566
Action: 'sts:AssumeRole'
531567

568+
569+
570+
532571
Outputs:
533572
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
534573
# Find out more about other implicit resources you can reference within SAM

0 commit comments

Comments
 (0)