Joey Yi Zhao
Joey Yi Zhao

Reputation: 42500

How can I configure database proxy on lambda in serverless.yml?

I am using serverless framework to provision infrastructure on AWS. And I need to add database proxy on my lambda but I couldn't find how to configure that. I have read the doc https://www.serverless.com/framework/docs/providers/aws/guide/functions/ but it doesn't mention anything relate to database proxy.

Below screenshot is the bottom of lambda in aws console. How can I add the proxy via serverless.yml?

enter image description here

Upvotes: 5

Views: 1540

Answers (1)

jeffmurphy
jeffmurphy

Reputation: 446

  1. Go to your RDS server and click on the proxy
  2. Copy the Proxy ARN
  3. Edit your serverless.yml and
provider:
  name: aws
  iam:
    role:
      statements:
        - Effect: "Allow"
          Action:
            - "rds-db:connect"
          Resource: "arn:aws:rds-db:us-east-1:123123123:admin:blah-123abc123abc/*"

Note that "rds" in the ARN was changed to "rds-db" and "db-proxy" in the ARN was changed to "admin" (the admin user of the database). sls deploy and check the lambda. You should see the proxy in the database proxy configuration section.

For example, the Proxy ARN I copied from RDS was

arn:aws:rds:us-east-1:123123123:db-proxy:blah-123abc123abc

and I edited it to be

arn:aws:rds-db:us-east-1:123123123:admin:blah-123abc123abc/*

Also, be sure your lambda is in the same Vpc as the RDS proxy or it will not be able to connect.

I am using:

% sls --version
Framework Core: 2.50.0
Plugin: 5.4.3
SDK: 4.2.3
Components: 3.13.2

Upvotes: 2

Related Questions