2021年3月31日水曜日

Lambda(Fargate自動起動・停止)

 1)関数の作成を選択





2)以下、設定。

関数名:

ランタイム:Python 3.xを選択


3)関数の作成を押す







IAMにて、ポリシーの作成を行う


















==========サンプルコード:==================

{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Effect": "Allow",

            "Action": [

                "ecs:DescribeServices",

                "ecs:UpdateService"

            ],

            "Resource": [

                "*"

            ]

        },

        {

            "Effect": "Allow",

            "Action": [

                "logs:CreateLogGroup",

                "logs:CreateLogStream",

                "logs:PutLogEvents"

            ],

            "Resource": "arn:aws:logs:*:*:*"

        }

    ]

}

=========================================



IAMロールを作成 















上記で、作成したポリシーを割り当てる。

















設定を選択















設定 ->アクセス権限 ->編集を押す。














既存ロール:上記で、作成したIAMロールを選択




















以下のようにコードを作成する。











============サンプルコード===============================

import boto3


from botocore.exceptions import ClientError

def lambda_handler(event, context):

    try:

        client = boto3.client('ecs')

        for cluster_name, service_name in [('test-cluster', 'test-service')]:

            service_update_result = client.update_service(

                cluster = cluster_name,

                service = service_name,

                desiredCount = 0 # コンテナの数

            )

            print(service_update_result)

    except ClientError as e:

        print("exceptin: %s" % e)

=======================================================


deploy ->Testを実施する。














0 件のコメント:

コメントを投稿

apache .htaccessのデバッグについて

dockerfileにapacheを入れているので、以下の記載により詳細なデバッグログが表示される  RUN sed -i 's/LogLevel warn/LogLevel info rewrite:trace8/g' /etc/apache2/a...