Lambdaで新しいNATゲートウェイを作るとき、名前を付けて起動させたいのですが、どうしたらよいですか?

0

Lambdaで新しいNATゲートウェイを作るとき、名前を付けて起動させたいのですが、どうしたらよいですか?

profile picture
Nagai
gefragt vor 4 Monaten297 Aufrufe
1 Antwort
0
Akzeptierte Antwort

動作確認していないですが、こんな感じで動かせると思います。
NAT Gatewayの名前はNameタグで設定するので"TagSpecifications"にある"Tags"で設定を行います。
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/create_nat_gateway.html

import boto3

ec2 = boto3.client('ec2')

def lambda_handler(event, context):

    ec2.create_nat_gateway(
        AllocationId='ElasticIPのID',
        SubnetId='NAT Gatewayを設定するサブネットID',
        TagSpecifications=[
            {
                'ResourceType': 'natgateway',
                'Tags': [
                    {
                        'Key': 'Name',
                        'Value': 'NAT Gatewayに設定したい名前'
                    },
                ]
            },
        ],
        ConnectivityType='public'
    )
profile picture
EXPERTE
beantwortet vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen