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"
        ]
      }
    }
  }
}
已提問 4 個月前檢視次數 203 次
1 個回答
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
已回答 4 個月前
profile pictureAWS
專家
kentrad
已審閱 4 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南