[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Let's create a VPC environment with CloudFormation (execution version)

Hello everyone,
this is Okazaki from the SRE team of the System Solutions Department.

last time , I would like to introduce a simple way to use "CloudFormation".
This time, I would like to actually build a VPC from the template file I filled out last time.

Create a stack

First, log in to your development server and register the API key of the user who will execute CloudFormation as shown below.

[root@localhost ~]# aws configure AWS Access Key ID [****************XXXX]: AWS Secret Access Key [************ ****XXXX]: Default region name [ap-northeast-1]: Default output format [XXXX]:

If you do not have the aws command, install it as follows.

[root@localhost ~]# yum install epel-release [root@localhost ~]# yum install python-pip [root@localhost ~]# pip install awscli

After confirming that the vpc.yml created last time exists, let's immediately build a VPC using the following command.

[root@localhost ~]# ls -l total 4 -rw-r--r--. 1 root root 1713 Mar 22 06:20 vpc.yml [root@localhost ~]# aws cloudformation create-stack \ > -- stack-name vpc \ > --region ap-northeast-1 \ > --template-body file://./vpc.yml

After execution, the creation process will proceed if it is displayed without any errors as shown below.

arn:aws:cloudformation:ap-northeast-1:189461266018:stack/vpc/7b29dce0-4c70-11e9-8b3c-0ee87e6fb924

You can check the status using the command below.
If the display shows "CREATE_COMPLETE", the resource is complete.

aws cloudformation describe-stacks --stack-name vpc STACKS 2019-03-28T02:12:32.683Z False False arn:aws:cloudformation:ap-northeast-1:189461266018:stack/vpc/f23007a0-50fe-11e9-88b0- 0e819627e6da vpc CREATE_COMPLETE DRIFTINFORMATION NOT_CHECKED PARAMETERS PublicSubnetCider 10.31.0.0/24 PARAMETERS ProjectCode test PARAMETERS VPCCider 10.31.0.0/16

Let's check whether the construction of each resource has been completed.

 

 

 

 

 

 

 

 

 

 

 

The VPC and subnet with the specified identifier were created without any problems.

Delete a resource

Now, I would like to delete all the resources that I created this time.
If you want to manually delete a resource, you need to go to each resource screen and delete each resource, but
resources created with CloudFormation can be deleted from a single console.
Return to the development server and issue the following command.

[root@localhost ~]# aws cloudformation delete-stack --stack-name vpc

Now, let's check the progress of the deletion.
Execute the command below, and if it says "DELETE_IN_PROGRESS", it means that the deletion is in progress.

[root@localhost ~]# aws cloudformation describe-stacks --stack-name vpc STACKS 2019-03-28T02:12:32.683Z 2019-03-28T02:20:53.902Z False False arn:aws:cloudformation:ap-northeast -1:189461266018:stack/vpc/f23007a0-50fe-11e9-88b0-0e819627e6da vpc DELETE_IN_PROGRESS DRIFTINFORMATION NOT_CHECKED PARAMETERS PublicSubnetCider 10.31.0.0/24 PARAMETERS ProjectCode test PARAMETERS VPCCider 10.3 1.0.0/16

Once the stack deletion is complete, the following error output will appear.

[root@localhost ~]# aws cloudformation describe-stacks --stack-name vpc An error occurred (ValidationError) when calling the DescribeStacks operation: Stack with id vpc does not exist

Now, let's check whether the deletion is actually completed.
I have confirmed that the VPC has disappeared.

 

 

 

 

 

 

Explanation

The following is an explanation of each command.

# aws cloudformation create-stack \ ↑ Declare to use cloudformation with aws cloudformation Command create stack with create-stack, delete-stack to delete > --stack-name vpc \ ↑ stack-name [name] Set the stack name > --region ap-northeast-1 \ ↑ --region [region] Set the region where you want to create the resource > --template-body file://./vpc.yml ↑ --template-body [File URL] Specify the URL of the template file

In this way, you can create a VPC with minimal commands.
In addition to this, if you want to change the values ​​of Parameters that were set last time, you can write it as follows.

# aws cloudformation create-stack \ > --stack-name vpc \ > --region ap-northeast-1 \ > --template-body file://./vpc.yml > --parameters \ > ParameterKey=ProjectCode, ParameterValue=test-beyondjapan \ > ParameterKey=VPCCider,ParameterValue="10.23.0.0/16" \ > ParameterKey=PublicSubnetCider,ParameterValue="10.23.0.0/24"

You can declare the use of each parameter in parameters, and specify the parameter ID in ParameterKey and the value in ParameterValue.

summary

This time, we were able to create and delete the stack and each resource from the console.
In this way, you can easily create and delete AWS resources by using CloudFormation.In
the previous and this time, we only talked about creating VPC, but next time we will introduce practical content such as creating EC2, so please try using it as well. .

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
573
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Junichiro Okazaki

Extensive experience in relocating and operating smartphone games.

He handles multi-cloud operations, server construction and relocation on a daily basis. As the number of cases has increased, I am considering how to improve the efficiency of my work. We often consider methods for relocating servers based on the merits of each cloud.

While we were relocating between clouds and from physical to cloud, we achieved two consecutive victories in a competition held by the Japan MSP Association.