Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摚 PSA for AWS Lambda: Easy Switch to cargo lambda 馃搱 #125

Open
kalzoo opened this issue Mar 13, 2024 · 1 comment
Open

馃摚 PSA for AWS Lambda: Easy Switch to cargo lambda 馃搱 #125

kalzoo opened this issue Mar 13, 2024 · 1 comment

Comments

@kalzoo
Copy link

kalzoo commented Mar 13, 2024

Hi everyone!

First of all, thanks to @softprops for building this tool and running it for several years.

If you're like me, you have some legacy projects using serverless-rust from the days when it was maintained. It was a great product that was irreplaceable when it launched and AWS didn't have great support for Rust.

But times have changed - the author has moved on to using SAM, and hey, open-source projects take a lot of time and effort to run. But now it's stuck in a broken state and you can't redeploy your once-working functions. It seems like this project has run its course.

But - fear not - it's easy to switch to the AWS-backed cargo lambda while sticking with serverless. I just did it in under 15 minutes. Here's how:

Step 1: Install & RTFM

Check out https://www.cargo-lambda.info/

Step 2: [Optional] Uninstall serverless-rust

just for sanity, to make sure it's fully out of your workflow.

  1. Remove from dependencies
  2. Remove from serverless.yml plugins field

Step 3: Select a Runtime

You'll want one of the OS-Only runtimes provided by AWS. I used provided.al2023 but you may want something else.

Replace this line:

runtime: rust

with

runtime: provided.al2023 # or your selected value

Step 4: Update Your Function Handlers

Update your serverless.yml like so:

package:
  individually: true

functions:
  hello-world:
    handler: does-not-matter-write-whatever
    package:
      # build with `cargo lambda build --output-format zip` and then fill in the build path. This is the default for `src/bin/hello_world.rs`
      artifact: target/lambda/hello_world/bootstrap.zip

Step 5: Build

cargo lambda build --output-format zip

Now that you have support for it (since this is pending issue #119 in serverless-rust), you can easily switch to ARM if you want:

cargo lambda build --output-format zip --arm64

just also make the switch in your serverless.yml:

provider:
  name: aws
  architecture: arm64

Step 6: Deploy

Just like always. Now, instead of building the project (like serverless-rust did), it'll just pick up your .zip file. You'll probably want to update your build scripts to reflect this two-step workflow.

sls deploy

That's all!

@softprops softprops pinned this issue Mar 13, 2024
@softprops
Copy link
Owner

Pinned this issue for greater visibility. It's great to see someone actively taking up the space. Great work @kalzoo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants