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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Functions in Stack Assume DockerContext is Unique #2514

Closed
metaskills opened this issue Jan 5, 2021 · 6 comments
Closed

Multiple Functions in Stack Assume DockerContext is Unique #2514

metaskills opened this issue Jan 5, 2021 · 6 comments

Comments

@metaskills
Copy link
Contributor

metaskills commented Jan 5, 2021

For Ruby on Rails with AWS Lambda using the Zip deployment package, we promoted using the same code with different function handlers. For example, one for Web and another for Jobs. This was easy to do with the and we even leveraged the Makefile build method to avoid building the same code twice. Tho this was not necessary. See here for details. https://lamby.custominktech.com/docs/activejob_and_lambda#3-new-jobslambda

Now that we have switched to containers I just realized a major bug with SAM that has stopped my work. Basically you can not do what SAM and the Zip package format did using Image. You can reproduce this issue by following this guide (https://aws.amazon.com/blogs/compute/using-container-image-support-for-aws-lambda-with-aws-sam/) and simply changing the DockerContext of the HolaWorldFunction to be the same ./hello-world used in the HelloWorldFunction. When you do this, you end up with one of a few errors depending on you method, guided, not, etc.

Error: No images found to deploy, try running sam build
Error: Unable to upload artifact None referenced by ImageUri parameter of HolaWorldFunction resource.

For Rails we will end up using the PWD so DockerContext: . vs a directory, but the error is still the same. We need to have the same image for multiple functions in the stack so we can allocate memory and timeouts differently for our "web" function or "job" functions. Hope that makes sense.

@metaskills
Copy link
Contributor Author

For my initial documentation I can work around this by having the "web" function handle both events.

Events:
  HttpApiProxy:
    Type: HttpApi
    Properties:
      ApiId: !Ref RailsHttpApi
  SQSJobs:
    Type: SQS
    Properties:
      Queue: !GetAtt JobsQueue.Arn
      BatchSize: 1

But this is not going to scale for our production usage. We need the same image for both functions like we had in the Zip format.

@metaskills
Copy link
Contributor Author

metaskills commented Jan 5, 2021

Screen Shot 2021-01-05 at 7 54 20 AMWas chatting with @singledigit online. He had called out:

The --image-repository flag uses the same repo for all Lambda function container images. But still a separate image for each function. The --image-repositories flag allows you to separate the images into multiple repositories. Not what you are looking for but wanted to clarify.

CORRECT. I fell back to --image-repositories because of this bug thinking it would help with the error(s) above. But technically I do want --image-repository to share the same repo. This was not the cause of the bug, it still exists but wanted to clear that up. He also suggested using the ImageUri as seen to the right, which allowed the build to take place for him.

I'm gonna try that as well as a symlink later tonight to see if that helps and report back. But still hoping this is a simple bug that can be fixed with SAM.

Thanks y'all.

@jfuss
Copy link
Contributor

jfuss commented Jan 5, 2021

Duplicate of #2466? It's hard to understand the problem you are hitting @metaskills but from my understanding it sounds like #2466 is what you are after (which already has a pr).

@metaskills
Copy link
Contributor Author

OK, so testing the ImageUri that @singledigit suggested leads to a dead end because the packaged.yml will end up like this. Note how the second ImageUri is not processed.

Resources:
  WebLambda:
    Type: AWS::Serverless::Function
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: .
    Properties:
      ImageUri: 012345678901.dkr.ecr.us-east-1.amazonaws.com/helloworldfunction:weblambda-6b6f5d9b54ab-latest
  JobLambda:
    Type: AWS::Serverless::Function
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: .
    Properties:
      ImageUri: helloworldfunction:latest

So my next attempt was to use a simple symlink like so.

lrwxr-xr-x   1 kencollins  staff     1B Jan  5 16:17 jobs -> .

And then point my jobs resource to:

  JobLambda:
    Type: AWS::Serverless::Function
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./jobs

This actually works but I'm still testing now.

@metaskills
Copy link
Contributor Author

@jfuss Thanks! I do think this is a duplicate of #2466. I can even try that DockerTag hack...

@metaskills
Copy link
Contributor Author

Closing in favor of #2466

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