Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ランダムでLGTM画像を返すAPIに必要なLambdaの変更を行う #57

Merged
merged 4 commits into from
Dec 20, 2021

Conversation

kobayashi-m42
Copy link
Member

@kobayashi-m42 kobayashi-m42 commented Dec 18, 2021

issueURL

#56

Doneの定義

#56 の完了条件が満たされていること

変更点概要

API Lambda から RDS と S3 にアクセスできるよう下記の変更を行なった

注:Amazon VPC エンドポイントを使用して、インターネットにアクセスせずに Amazon VPC 内からサポートされている AWS のサービスに接続することもできます。

  • API 用の Lambda から RDS Proxy に接続するために SecurityGroup ingress ルールを追加
  • API Lambda が RDS Proxy に接続する際に必要となるDB接続情報を Lambda の環境変数に追加

Comment on lines -20 to -31
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = [
"arn:aws:logs:*:*:*"
]
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWSLambdaVPCAccessExecutionRole に含まれているため削除

@@ -7,6 +7,8 @@ module "lambda" {
log_retention_in_days = local.log_retention_in_days
s3_bucket_name = data.terraform_remote_state.images.outputs.upload_images_bucket_name
lgtm_images_cdn_domain = data.terraform_remote_state.images.outputs.lgtm_images_cdn_domain
vpc_id = data.terraform_remote_state.network.outputs.vpc_id
subnet_ids = data.terraform_remote_state.network.outputs.subnet_public_ids
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private subnet は構築していないので、public subnet に Lambda を構築


resource "aws_iam_role_policy_attachment" "lambda_api_vpc_access_execution" {
role = aws_iam_role.lambda_api.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda がネットワークインターフェイスを作成および管理をできるように、実行ロールに AWSLambdaVPCAccessExecutionRoleを追加

参考:https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/configuration-vpc.html#vpc-permissions

@kobayashi-m42 kobayashi-m42 force-pushed the feature/issue56/vpc-lambda branch from aacbd9e to b819075 Compare December 19, 2021 15:17
@kobayashi-m42 kobayashi-m42 marked this pull request as ready for review December 19, 2021 15:18
Copy link
Member

@keitakn keitakn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応ありがとう🐱!VPC エンドポイントの設定方法勉強になった👍

LGTMeow

@kobayashi-m42 kobayashi-m42 merged commit 43a19cd into main Dec 20, 2021
@kobayashi-m42 kobayashi-m42 deleted the feature/issue56/vpc-lambda branch December 20, 2021 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants