0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分用メモ AWS タスク定義 CloudFormationサンプル

Posted at

AWSのCloudFormationでタスク定義作るサンプル。
ECS+Fargate+ECR+EFS。あとTomcat(これは名前しか登場しないか)。
タスクロールとタスク実行ロールは横着して同じの使ってます。

AWSTemplateFormatVersion: 2010-09-09

Parameters:
  ProjectName:
    Type: String
    Default: test

  ContainerImage:
    Type: String
    Default: <ECRのリポジトリURL>:<イメージのバージョン>
  EfsAccessPointId:
    Type: String
    Default: <アクセスポイントのID>
  EfsContainerPath:
    Type: String
    Default: <コンテナ内でEFSをマウントさせるパス>
  EfsFileSystemId:
    Type: String
    Default: <EFSのファイルシステムID>
  EcsExecRole:
    Type: String
    Default: <タスク実行ロールのARN>
  LogGroup:
    Type: String
    Default: <CloudWatchのロググループの名前>
  TomcatPort:
    Type: Number
    Default: <コンテナ側のポート(ここではTomcat使ってるのでこの名前)>

Resources:
  ECSTaskDefinition:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      Family: !Sub ${ProjectName}-ecs-task-def
      TaskRoleArn: !Ref EcsExecRole
      ExecutionRoleArn: !Ref EcsExecRole
      NetworkMode: awsvpc      
      Cpu: 256
      Memory: 512
      RequiresCompatibilities:
        - FARGATE
      Volumes:
        - Name: !Sub ${ProjectName}-ecs-efs-volume
          EFSVolumeConfiguration:
            AuthorizationConfig:
              AccessPointId: !Ref EfsAccessPointId
            FileSystemId: !Ref EfsFileSystemId
            TransitEncryption: 'ENABLED'
      ContainerDefinitions:
        - Name: !Sub ${ProjectName}-ecs-container
          Image: !Ref ContainerImage
          Essential: true
          PortMappings:
            - ContainerPort: !Ref TomcatPort
              Protocol: tcp
          MountPoints:
            - SourceVolume: !Sub ${ProjectName}-ecs-efs-volume
              ContainerPath: !Ref EfsContainerPath
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref LogGroup
              awslogs-region: !Ref 'AWS::Region'
              awslogs-stream-prefix: ecs
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?