LoginSignup
0
0

CloudFormationで作成したVPCエンドポイントにAWS CLIにてタグを作成しよう

Last updated at Posted at 2024-01-05

はじめに

CloudFormationで作成したVPCエンドポイントにAWS CLIにてタグを作成する。

CloudFormationにて事前にVPCエンドポイントを作成する必要があり、その際にOutputsにて、VPCエンドポイントIDを出力する必要がある。

スクリプト

create_vpc_endpoint_tags.sh
#!/bin/sh

cd `dirname $0`

STACK_NAME=${CloudFormationのスタック名}

# CloudFormationのスタックの出力からエンドポイントのIDを取得する
VPC_ENDPOINT_IDS=($(
    aws cloudformation describe-stacks \
        --stack-name ${STACK_NAME} \
        --query "Stacks[*].Outputs[*].OutputValue[]" \
        --output text
    ))
    
# CloudFormationのスタックの出力名を取得する
EXPORT_NAMES=$(
    aws cloudformation describe-stacks \
        --stack-name ${STACK_NAME} \
        --query "Stacks[*].Outputs[*].ExportName[]" \
        --output text
    )# VPCエンドポイントにタグを作成する
for i in ${!VPC_ENDPOINT_IDS[@]}
do
    aws ec2 delete-tags \
        --resources ${VPC_ENDPOINT_IDS[$i]}

    aws ec2 create-tags \
        --resources ${VPC_ENDPOINT_IDS[$i]} \
        --tags "Key=Name,Value=${EXPORT_NAMES[$i]}"
done

exit 0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0