Git Product home page Git Product logo

Comments (3)

crisboarna avatar crisboarna commented on July 18, 2024 1

Hey, thanks for the feature request !

It is doable, and have already done it in the past for other projects, although will not have time to do it this week, I will certainly implement it now that I can also take advantage of some of the new HCL syntax from 0.12.

As a guide for you, to configure the lambda in a VPC subnet you need to specify in the

aws_lambda_function

this property as well

  vpc_config {
    security_group_ids        = ["${data.aws_security_group.vpc_security_group.id}"]
    subnet_ids                = ["${data.aws_subnet.vpc_subnet_a.id}", "${data.aws_subnet.vpc_subnet_b.id}"]
  }

Given this is the module that also creates DynamoDB, I imagine you also need DynamoDB access. In the current format of the module it has direct access to DDB due to the lambda being exposed to WAN internet. Having it in VPC will require you to add a DynamoDB VPC Endpoint for the Lambda to access DDB.

resource "aws_vpc_endpoint" "vpc_dynamodb_endpoint" {
  vpc_id                                                      = "${module.vpc.vpc_id}"
  service_name                                           = "com.amazonaws.${var.region}.dynamodb"
  vpc_endpoint_type                                  = "Gateway"
}

as it is a specific route location, you will also need to add the endpoint in the route table

resource "aws_vpc_endpoint_route_table_association" "vpc_dynamodb_endpoint_route" {
  route_table_id                                              = "${module.subnets_public.route_table_id}"
  vpc_endpoint_id                                          = "${aws_vpc_endpoint.vpc_dynamodb_endpoint.id}"
}

Also don't forget to add the aws_vpc_endpoint.vpc_dynamodb_endpoint.prefix_list_id to a Security Group egress.

resource "aws_security_group_rule" "lambda_reminders_sec_egress_ipv4_dynamodb" {
  type                                                                   = "egress"
  from_port                                                          = 0
  to_port                                                              = 65535
  protocol                                                            = -1
  security_group_id                                              = "$}"
  prefix_list_ids                                                     = ["${aws_vpc_endpoint.vpc_dynamodb_endpoint.prefix_list_id}"]
}

from terraform-aws-api-gateway-lambda-dynamodb.

archenroot avatar archenroot commented on July 18, 2024

@crisboarna - thank you very much for super verbose answer, I will first get it working and eventually will extend the module. Its really nice work.

from terraform-aws-api-gateway-lambda-dynamodb.

crisboarna avatar crisboarna commented on July 18, 2024

v1.16.0 adds Lambda VPC/Layers support.

from terraform-aws-api-gateway-lambda-dynamodb.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.