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

Error when running sam local invoke (Sandbox.Failure) #6438

Closed
gustavofreze opened this issue Dec 12, 2023 · 6 comments
Closed

Error when running sam local invoke (Sandbox.Failure) #6438

gustavofreze opened this issue Dec 12, 2023 · 6 comments
Labels
area/local/invoke sam local invoke command type/question

Comments

@gustavofreze
Copy link

gustavofreze commented Dec 12, 2023

I'm building and then invoking my lambda function locally. When I do this, I encounter the error log below:

2023-12-12 02:22:12,867 | Starting a timer for 10 seconds for function 'Xpto'                                                                               
START RequestId: aa44dfa6-ec8f-4149-a65e-98e75e84458e Version: $LATEST
11 Dec 2023 23:22:13,330 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited without providing a reason
11 Dec 2023 23:22:13,330 [ERROR] (rapid) Invoke failed error=Runtime exited without providing a reason InvokeID=b17a6eea-8d8f-4ee6-bbd7-db0a8de2fb96
11 Dec 2023 23:22:13,331 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
2023-12-12 02:22:13,333 | Failed to deserialize response from RIE, returning the raw response as is 

I didn't find any specific references on how to proceed.

I will provide what I believe is relevant to the problem. I've already checked that main.py is not being called. That is, the error occurs before executing the code.

Project structure:

xpto/
┣ .aws/
┣ .aws-sam/
┣ event/
┣ src/
┃ ┗ main.py
┣ Dockerfile
┣ Makefile
┣ requirements.txt
┣ samconfig.toml
┗ template.yml

My Dockerfile:

FROM python:3.11-alpine

ENV AWS_PROFILE="default"
ENV AWS_CONFIG_FILE="/app/.aws/config"
ENV SAM_CLI_TELEMETRY=0

ENV VIRTUAL_ENV="/opt/venv"
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
ENV PIP_PATH="${VIRTUAL_ENV}/bin/pip"

WORKDIR /app

COPY src src
COPY .aws .aws
COPY requirements.txt requirements.txt

RUN python -m venv ${VIRTUAL_ENV} \
    && ${PIP_PATH} install --no-cache-dir --upgrade pip \
    && ${PIP_PATH} install --no-cache-dir --upgrade wheel awscli aws-sam-cli \
    && ${PIP_PATH} install --no-cache-dir --upgrade -r requirements.txt

CMD ["python", "-m", "src.main"]

My template.yml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Globals:
  Function:
    Timeout: 10
    MemorySize: 1024

Resources:
  Xpto:
    Type: AWS::Serverless::Function
    Properties:
      Layers:
        - !Ref Dependencies
      Runtime: python3.11
      ImageUri: xpto:latest
      PackageType: Image
      FunctionName: xpto
      Architectures:
        - x86_64
      Events:
        AtEveryMinute:
          Type: Schedule
          Properties:
            Enabled: true
            ScheduleExpression: rate(1 minute)
      Environment:
        Variables:
          TZ: "America/Sao_Paulo"
    Metadata:
      DockerTag: latest
      Dockerfile: Dockerfile
      DockerContext: .
      SamResourceId: Xpto
    Policies:
      - AWSLambdaBasicExecutionRole

  Dependencies:
    Type: AWS::Serverless::LayerVersion
    Properties:
      ContentUri: .
      RetentionPolicy: Retain
      CompatibleRuntimes:
        - python3.11
    Metadata:
      BuildMethod: python3.11
      SamResourceId: Dependencies
      BuildArchitecture: x86_64

My samconfig.toml:

version = 0.1

[default]
[default.global]
[default.global.parameters]
stack_name = "xpto"

[default.build]
[default.build.parameters]
cached = false
parallel = true
use_container = true
skip_pull_image = true

[default.sync]
[default.sync.parameters]
watch = true

[default.validate]
[default.validate.parameters]
lint = true

[default.local_invoke]
[default.local_invoke.parameters]
event = "event/event.json"
profile = "default"
no_event = false

My data in .aws:

  • config file:
[default]
output = json
region = us-east-1

And finally, the command I execute in my makefile:

SAM_BUILD = sam build
SAM_INVOKE = sam local invoke Xpto --debug
LAMBDA_IMAGE = xpto:latest
GENERATE_EVENT = python -m event.create_event

invoke:
	@docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/app -w /app --network=host \
        ${LAMBDA_IMAGE} sh -c "${SAM_BUILD} && ${GENERATE_EVENT} && ${SAM_INVOKE}"
@gustavofreze gustavofreze added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Dec 12, 2023
@lucashuy
Copy link
Contributor

Hi, I've deleted the credentials portion of your issue, even if one or more keys in that code block were pseudo values.

@hnnasit
Copy link
Contributor

hnnasit commented Dec 19, 2023

Hi there, sam local invoke runs lambda RIE in the background to emulate lambda invocation. Based on this code, it looks like RIE is expecting a lambda handler to be passed as an arg. Could you try passing the lambda handler for CMD instead of the python command to run the script? Example of image based app can be found here.

@hnnasit hnnasit added type/question area/local/invoke sam local invoke command and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Dec 19, 2023
@gustavofreze
Copy link
Author

Hello @hnnasit, thank you for your time. I changed it and tested it. I had the same error.

Copy link
Contributor

github-actions bot commented Apr 9, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@Laan33
Copy link

Laan33 commented May 8, 2024

@gustavofreze Did you manage to fix this ? If so what did you change 🙏 thank you

@gustavofreze
Copy link
Author

No, I couldn't fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command type/question
Projects
None yet
Development

No branches or pull requests

4 participants