Passer au contenu

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

0

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

demandé il y a 3 ans507 vues

1 réponse
0
Réponse acceptée

動作確認していないですが、こんな感じで動かせると思います。
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'
    )
EXPERT

répondu il y a 3 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.