diff --git a/.github/workflows/maze-runner.yml b/.github/workflows/maze-runner.yml index 49b337cd..9d89beb0 100644 --- a/.github/workflows/maze-runner.yml +++ b/.github/workflows/maze-runner.yml @@ -24,10 +24,6 @@ jobs: ruby-version: '3.3' bundler-cache: true - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - run: bundle exec maze-runner --no-source env: PYTHON_TEST_VERSION: ${{ matrix.python-version }} diff --git a/features/aws-lambda/handled.feature b/features/aws-lambda/handled.feature index bc9fb566..5d3bec59 100644 --- a/features/aws-lambda/handled.feature +++ b/features/aws-lambda/handled.feature @@ -1,32 +1,23 @@ Feature: Handled exceptions in AWS Lambda -@not-python-3.5 -@not-python-3.6 -@not-python-3.7 -@not-python-3.8 -@not-python-3.10 -@not-python-3.11 -@not-python-3.12 +# 3.9 is currently the minimum python version with a lambda runtime +@not-python-3.5 @not-python-3.6 @not-python-3.7 @not-python-3.8 Scenario: Handled exceptions are delivered in an AWS Lambda app - Given I build the "HelloWorldFunction" lambda in "features/fixtures/aws-lambda" - And I invoke the "HelloWorldFunction" lambda in "features/fixtures/aws-lambda" with the "events/event.json" event - Then the lambda response "body.message" equals "Did not crash!" - And the lambda response "statusCode" equals 200 - And the SAM exit code equals 0 - When I wait to receive an error - Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier - And the event "unhandled" is false - And the event "severity" equals "warning" - And the event "severityReason.type" equals "handledException" - And the exception "errorClass" equals "Exception" - And the exception "message" equals "hello there" - And the exception "type" equals "python" - And the "file" of stack frame 0 equals "app.py" - And the event "metaData.AWS Lambda Context.function_name" equals "HelloWorldFunction" - And the event "metaData.AWS Lambda Context.aws_request_id" is not null - And the event "metaData.AWS Lambda Event.path" equals "/hello" - And the event "metaData.AWS Lambda Event.httpMethod" equals "GET" - When I wait to receive a session - Then the session is valid for the session reporting API version "4.0" for the "Python Bugsnag Notifier" notifier - And the session payload has a valid sessions array - And the sessionCount "sessionsStarted" equals 1 + Given I run the "HelloWorldFunction" lambda + When I wait to receive an error + Then the error is valid for the error reporting API version "4.0" for the "Python Bugsnag Notifier" notifier + And the event "unhandled" is false + And the event "severity" equals "warning" + And the event "severityReason.type" equals "handledException" + And the exception "errorClass" equals "Exception" + And the exception "message" equals "hello there" + And the exception "type" equals "python" + And the "file" of stack frame 0 equals "handled.py" + And the event "metaData.AWS Lambda Context.function_name" equals "HelloWorldFunction" + And the event "metaData.AWS Lambda Context.aws_request_id" is not null + And the event "metaData.AWS Lambda Event.path" equals "/hello" + And the event "metaData.AWS Lambda Event.httpMethod" equals "GET" + When I wait to receive a session + Then the session is valid for the session reporting API version "4.0" for the "Python Bugsnag Notifier" notifier + And the session payload has a valid sessions array + And the sessionCount "sessionsStarted" equals 1 diff --git a/features/fixtures/aws-lambda/Dockerfile b/features/fixtures/aws-lambda/Dockerfile new file mode 100644 index 00000000..55d953a6 --- /dev/null +++ b/features/fixtures/aws-lambda/Dockerfile @@ -0,0 +1,10 @@ +ARG PYTHON_TEST_VERSION +FROM python:$PYTHON_TEST_VERSION + +# install the SAM CLI +ENV SAM_CLI_TELEMETRY=0 +RUN pip install --upgrade pip && pip install aws-sam-cli + +COPY temp-bugsnag-python/ /usr/src/bugsnag + +WORKDIR /usr/src/app diff --git a/features/fixtures/aws-lambda/events/event.json b/features/fixtures/aws-lambda/app/events/event.json similarity index 100% rename from features/fixtures/aws-lambda/events/event.json rename to features/fixtures/aws-lambda/app/events/event.json diff --git a/features/fixtures/aws-lambda/__init__.py b/features/fixtures/aws-lambda/app/hello_world/__init__.py similarity index 100% rename from features/fixtures/aws-lambda/__init__.py rename to features/fixtures/aws-lambda/app/hello_world/__init__.py diff --git a/features/fixtures/aws-lambda/hello_world/app.py b/features/fixtures/aws-lambda/app/hello_world/handled.py similarity index 92% rename from features/fixtures/aws-lambda/hello_world/app.py rename to features/fixtures/aws-lambda/app/hello_world/handled.py index c67bc3b7..34ca031a 100644 --- a/features/fixtures/aws-lambda/hello_world/app.py +++ b/features/fixtures/aws-lambda/app/hello_world/handled.py @@ -11,7 +11,7 @@ @bugsnag.aws_lambda_handler -def lambda_handler(event, context): +def handler(event, context): bugsnag.notify(Exception("hello there")) return { diff --git a/features/fixtures/aws-lambda/app/hello_world/requirements.txt b/features/fixtures/aws-lambda/app/hello_world/requirements.txt new file mode 100644 index 00000000..d7f6a11b --- /dev/null +++ b/features/fixtures/aws-lambda/app/hello_world/requirements.txt @@ -0,0 +1 @@ +/usr/src/bugsnag diff --git a/features/fixtures/aws-lambda/template.yaml b/features/fixtures/aws-lambda/app/template.yaml similarity index 83% rename from features/fixtures/aws-lambda/template.yaml rename to features/fixtures/aws-lambda/app/template.yaml index d7e83e35..59ba3d9c 100644 --- a/features/fixtures/aws-lambda/template.yaml +++ b/features/fixtures/aws-lambda/app/template.yaml @@ -5,20 +5,23 @@ Description: app Globals: Function: Timeout: 30 - MemorySize: 128 Environment: Variables: BUGSNAG_API_KEY: BUGSNAG_ERROR_ENDPOINT: BUGSNAG_SESSION_ENDPOINT: +Parameters: + Runtime: + Type: String + Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: hello_world/ - Handler: app.lambda_handler - Runtime: python3.9 + Handler: handled.handler + Runtime: !Ref Runtime Events: HelloWorld: Type: Api diff --git a/features/fixtures/aws-lambda/hello_world/__init__.py b/features/fixtures/aws-lambda/hello_world/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/features/fixtures/aws-lambda/hello_world/requirements.txt b/features/fixtures/aws-lambda/hello_world/requirements.txt deleted file mode 100644 index 9db38a4a..00000000 --- a/features/fixtures/aws-lambda/hello_world/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -./temp-bugsnag-python diff --git a/features/fixtures/aws-lambda/samconfig.toml b/features/fixtures/aws-lambda/samconfig.toml deleted file mode 100644 index ac0d93c7..00000000 --- a/features/fixtures/aws-lambda/samconfig.toml +++ /dev/null @@ -1,31 +0,0 @@ -# More information about the configuration file can be found here: -# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html -version = 0.1 - -[default] -[default.global.parameters] -stack_name = "app" - -[default.build.parameters] -cached = true -parallel = true - -[default.validate.parameters] -lint = true - -[default.deploy.parameters] -capabilities = "CAPABILITY_IAM" -confirm_changeset = true -resolve_s3 = true - -[default.package.parameters] -resolve_s3 = true - -[default.sync.parameters] -watch = true - -[default.local_start_api.parameters] -warm_containers = "EAGER" - -[default.local_start_lambda.parameters] -warm_containers = "EAGER" diff --git a/features/fixtures/docker-compose.yml b/features/fixtures/docker-compose.yml index 30764f9a..c8d4ae6b 100644 --- a/features/fixtures/docker-compose.yml +++ b/features/fixtures/docker-compose.yml @@ -12,3 +12,18 @@ services: - BUGSNAG_SESSION_ENDPOINT extra_hosts: - "host.docker.internal:host-gateway" + + aws-lambda: + build: + context: aws-lambda + args: + - PYTHON_TEST_VERSION + environment: + - BUGSNAG_API_KEY + - BUGSNAG_ERROR_ENDPOINT + - BUGSNAG_SESSION_ENDPOINT + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "./aws-lambda/app:/usr/src/app" diff --git a/features/steps/steps.rb b/features/steps/steps.rb index 9c38b34e..d2840fc5 100644 --- a/features/steps/steps.rb +++ b/features/steps/steps.rb @@ -1,7 +1,24 @@ -Given("I build the {string} lambda in {string}") do |name, path| - command = "sam build #{name}" +# PYTHON_TEST_VERSION is defined in env.rb +PARAMETER_OVERRIDES = "--parameter-overrides ParameterKey=Runtime,ParameterValue=python#{PYTHON_TEST_VERSION}" - _, exit_code = Maze::Runner.run_command("cd #{path} && #{command}") +Given("I build the {string} lambda") do |lambda_name| + step(%Q{I run the service "aws-lambda" with the command "sam build #{lambda_name} #{PARAMETER_OVERRIDES}"}) +end + +Given("I invoke the {string} lambda") do |lambda_name| + command = [ + "sam local invoke #{lambda_name}", + "--container-host host.docker.internal", + "--docker-volume-basedir $PWD/features/fixtures/aws-lambda/app/.aws-sam/build", + PARAMETER_OVERRIDES, + ] + + step(%Q{I run the service "aws-lambda" with the command "#{command.join(" ")}"}) +end - raise "Unable to build #{name}" unless exit_code.zero? +Given("I run the {string} lambda") do |lambda_name| + steps(" + Given I build the '#{lambda_name}' lambda + And I invoke the '#{lambda_name}' lambda + ") end diff --git a/features/support/env.rb b/features/support/env.rb index 8a6540dc..75846822 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,5 +1,7 @@ require "fileutils" +PYTHON_TEST_VERSION = ENV.fetch("PYTHON_TEST_VERSION") + Maze.hooks.before_all do # log to console, not the filesystem Maze.config.file_log = false @@ -45,8 +47,6 @@ Maze::Runner.environment["BUGSNAG_SESSION_ENDPOINT"] = "http://#{host}:#{Maze.config.port}/sessions" end -PYTHON_TEST_VERSION = ENV.fetch("PYTHON_TEST_VERSION") - 5.upto(100) do |minor_version| Before("@not-python-3.#{minor_version}") do skip_this_scenario if PYTHON_TEST_VERSION == "3.#{minor_version}"