Slide 8
Slide 8 text
EC2の状態を判断して起動/停止するコード(一部)
def lambda_handler(event, context):
client = boto3.client('ec2’)
#(中略 client.describe_instances()でインスタンスの情報を取得する)
if state == "stopped":
client.start_instances(
InstanceIds=[
instance['InstanceId'],
],
)
elif state == "running":
client.stop_instances(
InstanceIds=[
instance['InstanceId'],
],
)
© 2023 Fujitsu Limited
8