#Deploy Rust AWS Lambda

1 messages · Page 1 of 1 (latest)

quiet cloak
#

Hello, Im brand new to using Dagger and am trying to deploy AWS Lambdas written in Rust. I have been following the GO SDK Example - https://docs.dagger.io/183109/aws-lambda. I believe I have it working up until the last part.

response, err := aws. WithFile("/tmp/function.zip", build.File("/src/function.zip")). WithExec([]string{"lambda", "update-function-code", "--function-name", "myFunction", "--zip-file", "fileb:///tmp/function.zip"}). WithExec([]string{"lambda", "get-function-url-config", "--function-name", "myFunction"}). Stdout(ctx)

The error I get is that no zip is found. At what point is a zip created and what do I need to do for this section?

Thanks in advance for the help and please let me know if you have any questions.

pearl hinge
#

What happens when you run ls -lah /src on build container:

// before aws.WithFile line.
build.
  ...
  WithExec([]string{"ls", "-lah", "/src"})
slow turret
#

@quiet cloak in that guide, the zip is created here: WithExec([]string{"zip", "function.zip", "lambda"})

#

in the Go example, you'd need to replace to go compiling part with rust compiling

    build := client.Container().
        From("golang:1.20-alpine").
        WithExec([]string{"apk", "add", "zip"}).
        WithDirectory("/src", lambdaDir).
        WithWorkdir("/src").
        WithEnvVariable("GOOS", "linux").
        WithEnvVariable("GOARCH", "amd64").
        WithEnvVariable("CGO_ENABLED", "0").
        WithExec([]string{"go", "build", "-o", "lambda", "lambda.go"}).
        WithExec([]string{"zip", "function.zip", "lambda"})

The last step is the one that builds the zip file that the snipper you shared is trying to use

quiet cloak
#

Thanks @slow turret for the response. I see that now and have it working as I expected. I have one more issue. It is failing on the update-function-code execution now. It gives me an error of An error occurred (ResourceNotFoundException) when calling the UpdateFunctionCode operation: Function not found: .

Do I need to do something different when I create for the first time? I also tried create-function-code but it gave me the same error the CreateFunctionCode was not found.

Thanks for the help!

quiet cloak
#

Thanks again @slow turret . One more quick question. Is there an easy way to set this up so that I can create one if the function doesn't exist, otherwise update. I have a project with 3 handlers and if I want to add a 4th I'd like to just run my deploy command

slow turret
quiet cloak
#

Thanks. Apologize for the all the questions but it helps. Just an app dev guy trying to learn IaC

slow turret
quiet cloak
#

I tried using dagger to implement the create function as well. I am getting an error that the zip file can't be found.

There error I am getting is No such file or directory: 'get_email.zip' but you can see in previous steps exec zip get_email.zip target/release/get_email DONE

How can I find out where the zip went?

for _, f := range functions {
        response, err := aws.
            WithFile("tmp/"+f.binaryZip, build.File("/src/"+f.binaryZip)).
            WithExec([]string{"lambda", "create-function", "--function-name", f.functionName, "--zip-file", "fileb://" + f.binaryZip, "--runtime", "rust1.71", "--handler", f.binary, "--role", "ROLE-ARN"}).
            WithExec([]string{"lambda", "add-permission", "--function-name", f.functionName, "--statement-id", "FunctionURLAllowPublicAccess", "--action", "lambda:InvokeFunctionUrl", "--principal", "*", "--function-url-auth-type", "NONE"}).
            WithExec([]string{"lambda", "create-function-url-config", "--function-name", f.functionName, "--auth-type", "NONE"}).
            Stdout(ctx)
        if err != nil {
            panic(err)
        }
slow turret
#

also, seems like in the WithFile you missed a slash in the /tmp

#

so it should be WithFile("/tmp/"+f.binaryzip... and then "fileb:///tmp/"+f.binaryzip.... afterwards

quiet cloak
#

I know that this is an AWS question but I am getting an error on my role. I created a new role to use here and it is saying (AccessDeniedException) when calling the CreateFunction operation: Cross-account pass role is not allowed.. I believe this is because the entity type I selected is AWS Service and this isn't coming from an AWS Service. How do I create a role that I can use in my dagger pipeline?

slow turret
slow turret
#

@quiet cloak let us know if you were able to get ublocked 🙏

quiet cloak
#

I'm not but it's not a dagger issue. It is the way I'm doing my credentials. I followed what you sent and I still get the cross account pass role not allowed. I'm assuming that it is tied to the way that I have my IAM user setup and access key saved but struggling to get past that part

slow turret
rancid hazel
#

@quiet cloak when I worked on this previously, I found that you needed to call different AWS methods to create the function, create the function URL, update the function ZIP and update the function metadata/URL. If I remember correctly, there was also some specific sequencing gotchas to keep in mind ie. wait for the ZIP file to be uploaded and the function to be revised before using the function URL.

#

There is also an alternative approach to do this using a Docker container. I have some WIP Dagger code for that but AFAIR I couldn't get it working perfectly in all languages due to some hard-to-debug errors, and then unfortunately I ran out of time to investigate it in detail.

#

In any case, I hope you were able to solve the credentials issue you mentioned above. Let us know if you need help.

quiet cloak
#

I just finished up my meetings if you still have time to catch up in #911305510882513037 I think you would be able to point out my isses pretty quickly

slow turret
#

I have some time in about 30m

quiet cloak
#

Sounds good. I am in central time zone

slow turret
#

awesome. I'll ping you once I get back

slow turret
#

@quiet cloak sorry, completely forgot about this. LMK if you're around today

quiet cloak
#

I’m actually free the next hour if you have some time this morning

slow turret
#

we need to use the provided.al2 runtime

quiet cloak
#

Oh nice!

#

I'm deployed! Thank you so much @slow turret

slow turret
#

🚀

quiet cloak
#

FYI for anyone following this post on how to execute this.

It is delpoyed but failing to execute with the error Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]". I'm looking at how to fix my zip so I zip it up correctly and will let the channel know what I find