{"id":19705476,"url":"https://github.com/arun-gupta/lambda-rds-mysql","last_synced_at":"2025-10-25T21:04:13.509Z","repository":{"id":47211291,"uuid":"96482839","full_name":"arun-gupta/lambda-rds-mysql","owner":"arun-gupta","description":"Shows how to use a Lambda function to store data in an RDS instance","archived":false,"fork":false,"pushed_at":"2021-09-08T08:29:53.000Z","size":9,"stargazers_count":34,"open_issues_count":4,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-04-04T04:47:36.528Z","etag":null,"topics":["aws","database","hibernate","java","lambda","mysql","rds","serverless"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arun-gupta.png","metadata":{"files":{"readme":"readme.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-07T00:25:27.000Z","updated_at":"2023-02-28T21:59:50.000Z","dependencies_parsed_at":"2022-08-19T14:01:04.203Z","dependency_job_id":null,"html_url":"https://github.com/arun-gupta/lambda-rds-mysql","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arun-gupta%2Flambda-rds-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arun-gupta%2Flambda-rds-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arun-gupta%2Flambda-rds-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arun-gupta%2Flambda-rds-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arun-gupta","download_url":"https://codeload.github.com/arun-gupta/lambda-rds-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224178177,"owners_count":17268822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","database","hibernate","java","lambda","mysql","rds","serverless"],"created_at":"2024-11-11T21:28:32.026Z","updated_at":"2025-10-25T21:04:13.441Z","avatar_url":"https://github.com/arun-gupta.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"= AWS Lambda, RDS and Java\n\nThis project shows how to manipulate a database table in MySQL from an AWS Lambda function. The MySQL instance is hosted using Amazon Relational Database Service (RDS). AWS Lambda function is written using Java and packaged using Maven. Serverless Application Model (SAM) is used to deploy the Lambda function. AWS CLI is used to invoke the function.\n\n== Create and Configure RDS\n\n. Create RDS instance\n+\n```\naws rds create-db-instance \\\n    --db-instance-identifier LambdaMySQLTest \\\n    --db-instance-class db.r3.large \\\n    --engine MySQL \\\n    --port 3006 \\\n    --allocated-storage 5 \\\n    --db-name ExampleDB \\\n    --master-username master \\\n    --master-user-password master123 \\\n    --backup-retention-period 3 \n```\n+\n. Create inbound role for the security group:\n.. Get security group id:\n+\n```\naws rds describe-db-instances | jq \".DBInstances[].VpcSecurityGroups[].VpcSecurityGroupId\"\n```\n+\n.. Add inbound role:\n+\n```\naws ec2 authorize-security-group-ingress --group-id \u003cgroup-id\u003e --protocol all --port 3006 --cidr 0.0.0.0/0\n```\n+\n. Get instance id:\n+\n```\naws rds describe-db-instances | jq \".DBInstances[0].Endpoint.Address\"\n```\n+\n. Install MySQL client: `brew install mysql`\n. Create a table and add some rows `mysql -h \u003cendpoint\u003e -P 3306 -u master -pmaster123`:\n+\n```\nmysql: [Warning] Using a password on the command line interface can be insecure.\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 43\nServer version: 5.6.35-log MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql\u003e use ExampleDB;\nDatabase changed\nmysql\u003e CREATE TABLE EMPLOYEE(id int NOT NULL, name VARCHAR(20), PRIMARY KEY(id));\nQuery OK, 0 rows affected (0.03 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (1, \"Penny\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (2, \"Sheldon\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (3, \"Leonard\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (4, \"Howard\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (5, \"Raj\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (6, \"Amy\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e INSERT INTO EMPLOYEE (id, name) VALUES (7, \"Bernadette\");\nQuery OK, 1 row affected (0.02 sec)\n\nmysql\u003e exit;\nBye\n```\n\n== Package and Deploy Lambda Function\n\n. Create a package: `mvn package`\n. Upload to S3: `mvn install`\n. Deploy Lambda: `aws cloudformation deploy --template-file app.yml --stack-name employee`\n. Invoke Lambda:\n+\n```\naws lambda invoke \\\n--function-name Employee \\\n--payload '{ \"id\": 10, \"name\": \"Smith\" }' \\\nemployee.out\n```\n+\n. Delete Lambda: `aws cloudformation delete-stack --stack-name employee`\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farun-gupta%2Flambda-rds-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farun-gupta%2Flambda-rds-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farun-gupta%2Flambda-rds-mysql/lists"}