Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@mkawanee

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

More than 1 year has passed since last update.

改善

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"
}

参照

0
Help us understand the problem. What is going on with this article?
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
mkawanee
集団知性に感謝

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?