Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/customink/mysql2-lambda

Precompiled Mysql2 Gem for AWS Lambda
https://github.com/customink/mysql2-lambda

aws aws-lambda fullstack-serverless mysql mysql2 rds rds-proxy ruby-on-rails

Last synced: about 1 month ago
JSON representation

Precompiled Mysql2 Gem for AWS Lambda

Awesome Lists containing this project

README

        

⚠️ Given Lambda Containers are a thing now... and coupled with the fact that there are no AWS provided Amazon Linux 2 / Lambda containers higher than Ruby 2.7, I'd like to consider this project deprecated in favor of using custom images with the RIC installed. This is really easy to do and I outlined it here for those curious. https://github.com/customink/lamby-cookiecutter/pull/21

[![Test](https://github.com/customink/mysql2-lambda/actions/workflows/test.yml/badge.svg)](https://github.com/customink/mysql2-lambda/actions/workflows/test.yml)

# Mysql2 Lambda Gem

Lamby: Simple Rails & AWS Lambda Integration using Rack.Very simple [Mysql2](https://github.com/brianmario/mysql2) gem precompiled for Amazon Linux 1 & 2 (Ruby 2.5 & 2.7) with statically linked `libmysqlclient` ready for any AWS Lambda usage, including Rails. Add it to your Gemfile:

```ruby
# When using Rails.
gem 'mysql2-lambda'

# When NOT using Rails.
gem 'mysql2-lambda', require: 'mysql2'
```

Part of a suite of open source projects from **[Lamby: Simple Rails & AWS Lambda Integration using Rack.](https://github.com/customink/lamby)** Details include:

- Tested on Ruby 2.5.x & 2.7.x
- Small Size! Only 5 Megabytes. No Lambda Layers needed!
- Works with any MySQL connection. Including RDS Proxy.

## Methodology

We used the `amazon/aws-sam-cli-build-image-ruby2.5` Docker image from the [SAM CLI](https://github.com/aws/aws-sam-cli) project to build the MySQL Connector/C's `libmysqlclient`. From there we ensure the Mysql2 gem statically includes that library. The resulting packaged gem and `mysql2.so` file looks something like this.

```shell
$ ldd mysql2.so
linux-vdso.so.1 => (0x00007ffcb15d4000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa8ebd21000)
librt.so.1 => /lib64/librt.so.1 (0x00007fa8ebb19000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa8eb8fd000)
libgmp.so.10 => /usr/lib64/libgmp.so.10 (0x00007fa8eb687000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa8eb483000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fa8eb24c000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa8eaf4a000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa8eab7c000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa8ea966000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa8ec72e000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fa8ea764000)
```

## Development

Clone or fork this repository, make sure you have Docker installed, then run the following commands.

```shell
./bin/setup
./bin/build
```

You will now have a packaged gem in the root of your project. Simple tests to make sure it works.

```shell
./bin/test 2.5
./bin/test 2.7
```

## License

Thanks to all the contributors of the `Mysql2` (https://github.com/brianmario/mysql2) gem. The license here is the same as that. MIT.

## Code of Conduct

Everyone interacting in the Mysql2 Lambda project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/customink/mysql2-lambda/blob/master/CODE_OF_CONDUCT.md).