How to connect lambda function with RDS Databases with CFT

0

I have created a CFT to create the lambda function, the function is getting created. Now I want to connect it to the database. In the console there is option to connect to RDS database but in CFT I am not finding any.

lambda function doc:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "The template for API gateway stage.",
  "Parameters": {
    "projectName": {
      "Type": "String"
    },
    "role": {
      "Type": "String"
    },
    "imageUri": {
      "Type": "String"
    },
    "securityGroupIDs": {
      "Type": "CommaDelimitedList"
    }
  },
  "Resources": {
    "lambda": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Code": {
          "ImageUri": {
            "Ref": "imageUri"
          }
        },
        "FunctionName": {
          "Fn::Sub": "${projectName}-lambda"
        },
        "PackageType": "Image",
        "Role": {
          "Ref": "role"
        },
        "Timeout": 10,
        "VpcConfig": {
          "Ipv6AllowedForDualStack": false,
          "SecurityGroupIds": {
            "Ref": "securityGroupIDs"
          },
          "SubnetIds": "<enforced_value>"
        }
      }
    }
  },
  "Outputs": {
    "functionName": {
      "Description": "The custom lambda function name.",
      "Value": {
        "Ref": "lambda"
      }
    },
    "arn": {
      "Description": "The ARN of custom lambda function.",
      "Value": {
        "Fn::GetAtt": [
          "lambda",
          "Arn"
        ]
      }
    }
  }
}
asked 3 months ago184 views
1 Answer
1

In order to communicate with your RDS instance from a Lambda function (assuming you are following best practice and not making your RDS available over the internet) is to place your Lambda function in a VPC and allowing routing and Security Group access to the RDS instance. The section for configuring your Lambda to be within a VPC from CloudFormation can be found here.

profile pictureAWS
danjhd
answered 3 months ago
profile pictureAWS
EXPERT
kentrad
reviewed 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions