I have a AWS Lambda application deployed via Serverless Framework. It needs a database, the CloudFormation for which I include in serverless.yaml's resources section.
With minimal knowledge of VPCs, subnets, and security groups, my goal is the following:
- Create/update a MySQL RDS instance with the
serverless deploys. - The functions in the Lambda application should be able to access the database.
- The database should be accessible publicly with a password, so I can connect with MySQL tools like Sequel Ace from my computer.
What I've tried so far:
I've attempted this with the below serverless configuration. It creates the database but it doesn't fulfill #2 and #3.
I've also tried setting provider.vpc.securityGroupIds and provider.vpc.subnetIds in serverless.yaml to the same ones the RDS instance uses, to no avail.
serverless.yaml
(the relevant sections)
service: myapp
provider:
name: aws
runtime: provided.al2
lambdaHashingVersion: 20201221
functions:
console:
handler: bin/console
timeout: 120 # in seconds
layers:
- ${bref:layer.php-80} # PHP
- ${bref:layer.console} # The "console" layer
resources:
Resources:
# RDS instance
ProductDatabase:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: 5
DBInstanceClass: db.t3.micro
DBName: myapp
Engine: mysql
EngineVersion: 8.0.25
MasterUsername: myappuser
MasterUserPassword: redacted
PubliclyAccessible: true