$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.dynamodb.aws_dynamodb_table.employee_list will be created
+ resource "aws_dynamodb_table" "employee_list" {
+ arn = (known after apply)
+ billing_mode = "PAY_PER_REQUEST"
+ hash_key = "EmployeeId"
+ id = (known after apply)
+ name = "sample1_employee_list"
+ read_capacity = (known after apply)
+ stream_arn = (known after apply)
+ stream_label = (known after apply)
+ stream_view_type = (known after apply)
+ tags_all = (known after apply)
+ write_capacity = (known after apply)
+ attribute {
+ name = "EmployeeId"
+ type = "S"
}
+ point_in_time_recovery {
+ enabled = (known after apply)
}
+ server_side_encryption {
+ enabled = (known after apply)
+ kms_key_arn = (known after apply)
}
+ ttl {
+ attribute_name = (known after apply)
+ enabled = (known after apply)
}
}
# module.dynamodb.aws_dynamodb_table_item.employee_list_item will be created
+ resource "aws_dynamodb_table_item" "employee_list_item" {
+ hash_key = "EmployeeId"
+ id = (known after apply)
+ item = jsonencode(
{
+ EmployeeId = {
+ S = "a00000110"
}
+ FirstName = {
+ S = "Taro"
}
+ LastName = {
+ S = "Momo"
}
+ Office = {
+ S = "Nagoya"
}
}
)
+ table_name = "sample1_employee_list"
}
Plan: 2 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.dynamodb.aws_dynamodb_table.employee_list: Creating...
module.dynamodb.aws_dynamodb_table.employee_list: Still creating... [10s elapsed]
module.dynamodb.aws_dynamodb_table.employee_list: Creation complete after 15s [id=sample1_employee_list]
module.dynamodb.aws_dynamodb_table_item.employee_list_item: Creating...
module.dynamodb.aws_dynamodb_table_item.employee_list_item: Creation complete after 0s [id=sample1_employee_list|EmployeeId||a00000110|]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate
terraform コマンドを実行します。main.tf のディレクトリで、以下のコマンドを実行します。terraform plan にエラーがなければ、terraform apply を実行します。
terraform init
terraform plan
terraform apply
IAM のリソースのリソースをデプロイします。
$ terraform apply
module.dynamodb.aws_dynamodb_table.employee_list: Refreshing state... [id=sample1_employee_list]
module.dynamodb.aws_dynamodb_table_item.employee_list_item: Refreshing state... [id=sample1_employee_list|EmployeeId||a00000110|]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.iam.aws_iam_role.tr_lambda_role will be created
+ resource "aws_iam_role" "tr_lambda_role" {
+ arn = (known after apply)
+ assume_role_policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sts:AssumeRole"
+ Effect = "Allow"
+ Principal = {
+ Service = "lambda.amazonaws.com"
}
+ Sid = ""
},
]
+ Version = "2012-10-17"
}
)
+ create_date = (known after apply)
+ force_detach_policies = false
+ id = (known after apply)
+ managed_policy_arns = (known after apply)
+ max_session_duration = 3600
+ name = "sample1_tr_lambda_role"
+ name_prefix = (known after apply)
+ path = "/"
+ tags_all = (known after apply)
+ unique_id = (known after apply)
+ inline_policy {
+ name = (known after apply)
+ policy = (known after apply)
}
}
# module.iam.aws_iam_role_policy.tr_lambda_role_policy_policy will be created
+ resource "aws_iam_role_policy" "tr_lambda_role_policy_policy" {
+ id = (known after apply)
+ name = "sample1_tr_lambda_policy"
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = [
+ "dynamodb:GetItem",
]
+ Effect = "Allow"
+ Resource = [
+ "arn:aws:dynamodb:us-east-1:111111111111:table/sample1_employee_list",
]
},
]
+ Version = "2012-10-17"
}
)
+ role = (known after apply)
}
# module.iam.aws_iam_role_policy_attachment.tr_lambda_role_policy_attach will be created
+ resource "aws_iam_role_policy_attachment" "tr_lambda_role_policy_attach" {
+ id = (known after apply)
+ policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
+ role = "sample1_tr_lambda_role"
}
Plan: 3 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.iam.aws_iam_role.tr_lambda_role: Creating...
module.iam.aws_iam_role.tr_lambda_role: Creation complete after 2s [id=sample1_tr_lambda_role]
module.iam.aws_iam_role_policy_attachment.tr_lambda_role_policy_attach: Creating...
module.iam.aws_iam_role_policy.tr_lambda_role_policy_policy: Creating...
module.iam.aws_iam_role_policy_attachment.tr_lambda_role_policy_attach: Creation complete after 1s [id=sample1_tr_lambda_role-20220414154047163300000001]
module.iam.aws_iam_role_policy.tr_lambda_role_policy_policy: Creation complete after 1s [id=sample1_tr_lambda_role:sample1_tr_lambda_policy]
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate
terraform コマンドを実行します。main.tf のディレクトリで、以下のコマンドを実行します。terraform plan にエラーがなければ、terraform apply を実行します。
terraform init
terraform plan
terraform apply
Lambda のリソースのリソースをデプロイします。
$ terraform apply
module.lambda.data.archive_file.tr_lambda: Refreshing state...
module.iam.aws_iam_role.tr_lambda_role: Refreshing state... [id=sample1_tr_lambda_role]
module.dynamodb.aws_dynamodb_table.employee_list: Refreshing state... [id=sample1_employee_list]
module.dynamodb.aws_dynamodb_table_item.employee_list_item: Refreshing state... [id=sample1_employee_list|EmployeeId||a00000110|]
module.iam.aws_iam_role_policy.tr_lambda_role_policy_policy: Refreshing state... [id=sample1_tr_lambda_role:sample1_tr_lambda_policy]
module.iam.aws_iam_role_policy_attachment.tr_lambda_role_policy_attach: Refreshing state... [id=sample1_tr_lambda_role-20220414154047163300000001]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.lambda.aws_lambda_function.tr_lambda will be created
+ resource "aws_lambda_function" "tr_lambda" {
+ architectures = (known after apply)
+ arn = (known after apply)
+ filename = "../modules/lambda/upload/lambda.zip"
+ function_name = "sample1_tr_lambda"
+ handler = "tr_lambda.handler"
+ id = (known after apply)
+ invoke_arn = (known after apply)
+ last_modified = (known after apply)
+ memory_size = 128
+ package_type = "Zip"
+ publish = false
+ qualified_arn = (known after apply)
+ reserved_concurrent_executions = -1
+ role = "arn:aws:iam::111111111111:role/sample1_tr_lambda_role"
+ runtime = "python3.8"
+ signing_job_arn = (known after apply)
+ signing_profile_version_arn = (known after apply)
+ source_code_hash = "VWlQRjcX2al8ylHGGDu1dB2AUs17ONMmbne3piGvLYg="
+ source_code_size = (known after apply)
+ tags_all = (known after apply)
+ timeout = 29
+ version = (known after apply)
+ environment {
+ variables = {
+ "TABLE_NAME" = "sample1_employee_list"
}
}
+ ephemeral_storage {
+ size = (known after apply)
}
+ tracing_config {
+ mode = (known after apply)
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.lambda.aws_lambda_function.tr_lambda: Creating...
module.lambda.aws_lambda_function.tr_lambda: Creation complete after 7s [id=sample1_tr_lambda]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate
terraform コマンドを実行します。main.tf のディレクトリで、以下のコマンドを実行します。terraform plan にエラーがなければ、terraform apply を実行します。
terraform init
terraform plan
terraform apply
API Gateway のリソースのリソースをデプロイします。
$ terraform apply
module.lambda.data.archive_file.tr_lambda: Refreshing state... [id=68d1ce2bad53ef6bcfa33c7157b6a910411e399e]
module.iam.aws_iam_role.tr_lambda_role: Refreshing state... [id=sample1_tr_lambda_role]
module.dynamodb.aws_dynamodb_table.employee_list: Refreshing state... [id=sample1_employee_list]
module.dynamodb.aws_dynamodb_table_item.employee_list_item: Refreshing state... [id=sample1_employee_list|EmployeeId||a00000110|]
module.iam.aws_iam_role_policy.tr_lambda_role_policy_policy: Refreshing state... [id=sample1_tr_lambda_role:sample1_tr_lambda_policy]
module.iam.aws_iam_role_policy_attachment.tr_lambda_role_policy_attach: Refreshing state... [id=sample1_tr_lambda_role-20220414154047163300000001]
module.lambda.aws_lambda_function.tr_lambda: Refreshing state... [id=sample1_tr_lambda]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.api_gateway.aws_api_gateway_deployment.tr_api will be created
+ resource "aws_api_gateway_deployment" "tr_api" {
+ created_date = (known after apply)
+ execution_arn = (known after apply)
+ id = (known after apply)
+ invoke_url = (known after apply)
+ rest_api_id = (known after apply)
+ stage_name = "test"
+ triggers = {
+ "redeployment" = "dmFyaWFibGUgInByZWZpeCIgewogIHR5cGUgPSBzdHJpbmcKfQoKdmFyaWFibGUgInRyX2xhbWJkYS1pbnZva2UtYXJuIiB7CiAgdHlwZSA9IHN0cmluZwp9CgpyZXNvdXJjZSAiYXdzX2FwaV9nYXRld2F5X3Jlc3RfYXBpIiAidHJfYXBpIiB7CiAgbmFtZSA9ICIke3Zhci5wcmVmaXh9X3RyX2FwaSIKfQoKcmVzb3VyY2UgImF3c19hcGlfZ2F0ZXdheV9tZXRob2QiICJ0cl9hcGlfZ2V0IiB7CiAgYXV0aG9yaXphdGlvbiA9ICJOT05FIgogIGh0dHBfbWV0aG9kICAgPSAiR0VUIgogIHJlc291cmNlX2lkICAgPSBhd3NfYXBpX2dhdGV3YXlfcmVzdF9hcGkudHJfYXBpLnJvb3RfcmVzb3VyY2VfaWQKICByZXN0X2FwaV9pZCAgID0gYXdzX2FwaV9nYXRld2F5X3Jlc3RfYXBpLnRyX2FwaS5pZAp9CgpyZXNvdXJjZSAiYXdzX2FwaV9nYXRld2F5X2ludGVncmF0aW9uIiAidHJfYXBpX2dldCIgewogIGh0dHBfbWV0aG9kICAgICAgICAgICAgID0gYXdzX2FwaV9nYXRld2F5X21ldGhvZC50cl9hcGlfZ2V0Lmh0dHBfbWV0aG9kCiAgcmVzb3VyY2VfaWQgICAgICAgICAgICAgPSBhd3NfYXBpX2dhdGV3YXlfcmVzdF9hcGkudHJfYXBpLnJvb3RfcmVzb3VyY2VfaWQKICByZXN0X2FwaV9pZCAgICAgICAgICAgICA9IGF3c19hcGlfZ2F0ZXdheV9yZXN0X2FwaS50cl9hcGkuaWQKICBpbnRlZ3JhdGlvbl9odHRwX21ldGhvZCA9ICJQT1NUIgogIHR5cGUgICAgICAgICAgICAgICAgICAgID0gIkFXU19QUk9YWSIKICB1cmkgICAgICAgICAgICAgICAgICAgICA9IHZhci50cl9sYW1iZGEtaW52b2tlLWFybgp9CgpyZXNvdXJjZSAiYXdzX2FwaV9nYXRld2F5X2RlcGxveW1lbnQiICJ0cl9hcGkiIHsKICBkZXBlbmRzX29uID0gWwogICAgYXdzX2FwaV9nYXRld2F5X2ludGVncmF0aW9uLnRyX2FwaV9nZXQKICBdCiAgcmVzdF9hcGlfaWQgPSBhd3NfYXBpX2dhdGV3YXlfcmVzdF9hcGkudHJfYXBpLmlkCiAgc3RhZ2VfbmFtZSAgPSAidGVzdCIKICB0cmlnZ2VycyA9IHsKICAgIHJlZGVwbG95bWVudCA9IGZpbGViYXNlNjQoIiR7cGF0aC5tb2R1bGV9L2FwaS1nYXRld2F5LnRmIikKICB9Cn0KCm91dHB1dCAidHJfYXBpLWV4ZWN1dGlvbi1hcm4iIHsKICB2YWx1ZSA9IGF3c19hcGlfZ2F0ZXdheV9yZXN0X2FwaS50cl9hcGkuZXhlY3V0aW9uX2Fybgp9"
}
}
# module.api_gateway.aws_api_gateway_integration.tr_api_get will be created
+ resource "aws_api_gateway_integration" "tr_api_get" {
+ cache_namespace = (known after apply)
+ connection_type = "INTERNET"
+ http_method = "GET"
+ id = (known after apply)
+ integration_http_method = "POST"
+ passthrough_behavior = (known after apply)
+ resource_id = (known after apply)
+ rest_api_id = (known after apply)
+ timeout_milliseconds = 29000
+ type = "AWS_PROXY"
+ uri = "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:111111111111:function:sample1_tr_lambda/invocations"
}
# module.api_gateway.aws_api_gateway_method.tr_api_get will be created
+ resource "aws_api_gateway_method" "tr_api_get" {
+ api_key_required = false
+ authorization = "NONE"
+ http_method = "GET"
+ id = (known after apply)
+ resource_id = (known after apply)
+ rest_api_id = (known after apply)
}
# module.api_gateway.aws_api_gateway_rest_api.tr_api will be created
+ resource "aws_api_gateway_rest_api" "tr_api" {
+ api_key_source = (known after apply)
+ arn = (known after apply)
+ binary_media_types = (known after apply)
+ created_date = (known after apply)
+ description = (known after apply)
+ disable_execute_api_endpoint = (known after apply)
+ execution_arn = (known after apply)
+ id = (known after apply)
+ minimum_compression_size = -1
+ name = "sample1_tr_api"
+ policy = (known after apply)
+ root_resource_id = (known after apply)
+ tags_all = (known after apply)
+ endpoint_configuration {
+ types = (known after apply)
+ vpc_endpoint_ids = (known after apply)
}
}
# module.lambda.aws_lambda_permission.tr_lambda_permit will be created
+ resource "aws_lambda_permission" "tr_lambda_permit" {
+ action = "lambda:InvokeFunction"
+ function_name = "arn:aws:lambda:us-east-1:111111111111:function:sample1_tr_lambda"
+ id = (known after apply)
+ principal = "apigateway.amazonaws.com"
+ source_arn = (known after apply)
+ statement_id = "AllowAPIGatewayGetTrApi"
}
Plan: 5 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.api_gateway.aws_api_gateway_rest_api.tr_api: Creating...
module.api_gateway.aws_api_gateway_rest_api.tr_api: Creation complete after 1s [id=ii1wux2em1]
module.api_gateway.aws_api_gateway_method.tr_api_get: Creating...
module.lambda.aws_lambda_permission.tr_lambda_permit: Creating...
module.api_gateway.aws_api_gateway_method.tr_api_get: Creation complete after 1s [id=agm-ii1wux2em1-xo03v7lk60-GET]
module.api_gateway.aws_api_gateway_integration.tr_api_get: Creating...
module.api_gateway.aws_api_gateway_integration.tr_api_get: Creation complete after 0s [id=agi-ii1wux2em1-xo03v7lk60-GET]
module.api_gateway.aws_api_gateway_deployment.tr_api: Creating...
module.lambda.aws_lambda_permission.tr_lambda_permit: Creation complete after 1s [id=AllowAPIGatewayGetTrApi]
module.api_gateway.aws_api_gateway_deployment.tr_api: Creation complete after 1s [id=q6drc4]
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate
ハンズオン5:結合テスト
クライアントから API Gateway にリクエストを投げ、レスポンスが期待通り返ることを確認します。