Help us understand the problem. What is going on with this article?

Elastic Beanstalk 指定時間だけインスタンスタイプを上げる

改善

12:00~13:00のみ負荷のかかるElastic Beanstalkの環境がある。
インスタンスタイプの調整で費用を抑える。
PMから指示がなくてもインフラはそうする。

lambda_function.lambda_handler

python3.8
import json
import boto3
from datetime import datetime

def lambda_handler(event, context):
    envName = str(event['env-name'])

    instanceType = ''
    currHour = datetime.now().hour + 9

    if currHour > 24:
        currHour = currHour - 24

    print(currHour)

    if(currHour == 11): #11時代に上げる
        instanceType = 'c5.xlarge'
    elif(currHour == 13): #13時代に下げる
        instanceType = 't3.micro'
    else:
        return 'NONE'

    client = boto3.client('elasticbeanstalk', region_name="ap-northeast-1")

    response = client.update_environment(
        EnvironmentName=envName,
        OptionSettings=[
            {
                'Namespace': 'aws:autoscaling:launchconfiguration',
                'OptionName': 'InstanceType',
                'Value': instanceType,
            }
        ],
    )

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }


CloudWatch Events

例)cron(5 * ? * * *)

テストイベント

{
  "env-name": "app-env"
}

参照

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした