2021年3月31日水曜日

ambda(EC2の自動起動・停止)

 1)ポリシーを作成する。












2)ロールの作成を行う。

上記で作成したポリシーをアタッチする。











■Lambda(関数作成)


関数作成を選択





1)1から作成

2)関数名:名前を記載。

3)ランタイム:Pyhton3.x







コードの入力を行う








設定 ->アクセス権限  ->編集を選択








上記で設定した、ロールを指定

保存押す

























コードの実行:

1)Deployを実行

2)Testを実施







■自動起動用コード

===============================-

import boto3

region = 'ap-northeast-1'

instances = [‘対象のインスタンス名’]

ec2 = boto3.client('ec2', region_name=region)


def lambda_handler(event, context):

    ec2.start_instances(InstanceIds=instances)

    print('started your instances: ' + str(instances))

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



■自動停止用コード

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

import boto3


region = 'ap-northeast-1'

instances = [‘対象のインスタンス名’]

ec2 = boto3.client('ec2', region_name=region)



def lambda_handler(event, context):

    ec2.stop_instances(InstanceIds=instances)

    print('stopped your instances: ' + str(instances))

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




0 件のコメント:

コメントを投稿

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

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