aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Unable to run `sam local start-api` using regular `.jar` file #2505

Open FieryCod opened 3 years ago

FieryCod commented 3 years ago

Description:

It seems to me that now AWS SAM does not allow to specify CodeUri as a path to .jar file when using sam local start-api.

Steps to reproduce:

  1. Clone https://github.com/ekoontz/holy-lambda/tree/choly-ectomy
  2. Go to examples/hello-lambda
  3. Run lein uberjar
  4. Run sam local start-api

Observed result:

2020-12-25 16:22:43,240 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2020-12-25 16:22:43,304 | local start-api command is called
2020-12-25 16:22:43,309 | Collected default values for parameters: {'Runtime': 'java8', 'Timeout': 40, 'MemorySize': 2000}
2020-12-25 16:22:43,328 | 3 resources found in the template
2020-12-25 16:22:43,328 | Found Serverless function with name='HelloLambdaFunction' and CodeUri='target/output.jar'
2020-12-25 16:22:43,328 | Found Serverless function with name='ByeLambdaFunction' and CodeUri='target/output.jar'
2020-12-25 16:22:43,331 | Collected default values for parameters: {'Runtime': 'java8', 'Timeout': 40, 'MemorySize': 2000}
2020-12-25 16:22:43,349 | 3 resources found in the template
2020-12-25 16:22:43,349 | Found '1' API Events in Serverless function with name 'HelloLambdaFunction'
2020-12-25 16:22:43,349 | Found '1' API Events in Serverless function with name 'ByeLambdaFunction'
2020-12-25 16:22:43,349 | Detected Inline Swagger definition
2020-12-25 16:22:43,349 | Lambda function integration not found in Swagger document at path='/' method='get'
2020-12-25 16:22:43,349 | Lambda function integration not found in Swagger document at path='/bye' method='get'
2020-12-25 16:22:43,349 | Found '0' APIs in resource 'ServerlessRestApi'
2020-12-25 16:22:43,349 | Removed duplicates from '0' Explicit APIs and '2' Implicit APIs to produce '2' APIs
2020-12-25 16:22:43,349 | 2 APIs found in the template
2020-12-25 16:22:43,351 | Mounting ByeLambdaFunction at http://127.0.0.1:3000/bye [GET]
2020-12-25 16:22:43,351 | Mounting HelloLambdaFunction at http://127.0.0.1:3000/ [GET]
2020-12-25 16:22:43,351 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2020-12-25 16:22:43,351 | Localhost server is starting up. Multi-threading = True
2020-12-25 16:22:43  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2020-12-25 16:22:46,437 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9,pl;q=0.8", "Cache-Control": "max-age=0", "Connection": "keep-alive", "Cookie": "_ga=GA1.1.588100546.1605526775; retargeter=1; _hjid=1cd5ce7b-806f-484d-b5bf-8233dc54d0a4; _gcl_au=1.1.1839864808.1605526778; sid=8db35e42-e22d-4925-9345-e0abf5edd022; _rollupUNLVR=GA1.1.588100546.1605526775; hidden-notifications=|_cookie; postcode=00-0101+; IdTokenN=eyJhbGciOiJub25lIn0.eyJzdWIiOiI2NTYxMjUiLCJlbWFpbCI6Im1zdGFjaHVyc2tpQGZyaXNjby5wbCIsInRva2VuX3VzYWdlIjoiaWRfdG9rZW4iLCJqdGkiOiJlODg5ZDU0Yy0zOGIwLTRjNDItYWM1Ny03ODhjN2I1YWU1NTEiLCJhdWQiOiJmcmlzY28iLCJhenAiOiJmcmlzY28iLCJuYmYiOjE2MDU4Njc2NDAsImV4cCI6MTYwNTg2ODg0MCwiaWF0IjoxNjA1ODY3NjQwLCJpc3MiOiJodHRwczovL2NvbW1lcmNlLnN0YWdpbmcuZnJpc2NvdGVzdC5jb20vIn0.; _ga_ZE0ZSB42J2=GS1.1.1605867322.3.1.1605871082.60; _xsrf=2|0408e9fd|a78095c4f7b568288faa44494995fd64|1607876733; username-localhost-8888=\"2|1:0|10:1608040169|23:username-localhost-8888|44:MDMxZWQwYTRiM2FlNDg5YmJmYWY2NTA3MTQ2YWFhZGE=|c5d471ff1fa782b50cc2aae57301ac0c2af1cbb6ede9285ddb166ac49a50bc60\"", "Host": "localhost:3000", "Sec-Ch-Ua": "\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"", "Sec-Ch-Ua-Mobile": "?0", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9,pl;q=0.8"], "Cache-Control": ["max-age=0"], "Connection": ["keep-alive"], "Cookie": ["_ga=GA1.1.588100546.1605526775; retargeter=1; _hjid=1cd5ce7b-806f-484d-b5bf-8233dc54d0a4; _gcl_au=1.1.1839864808.1605526778; sid=8db35e42-e22d-4925-9345-e0abf5edd022; _rollupUNLVR=GA1.1.588100546.1605526775; hidden-notifications=|_cookie; postcode=00-0101+; IdTokenN=eyJhbGciOiJub25lIn0.eyJzdWIiOiI2NTYxMjUiLCJlbWFpbCI6Im1zdGFjaHVyc2tpQGZyaXNjby5wbCIsInRva2VuX3VzYWdlIjoiaWRfdG9rZW4iLCJqdGkiOiJlODg5ZDU0Yy0zOGIwLTRjNDItYWM1Ny03ODhjN2I1YWU1NTEiLCJhdWQiOiJmcmlzY28iLCJhenAiOiJmcmlzY28iLCJuYmYiOjE2MDU4Njc2NDAsImV4cCI6MTYwNTg2ODg0MCwiaWF0IjoxNjA1ODY3NjQwLCJpc3MiOiJodHRwczovL2NvbW1lcmNlLnN0YWdpbmcuZnJpc2NvdGVzdC5jb20vIn0.; _ga_ZE0ZSB42J2=GS1.1.1605867322.3.1.1605871082.60; _xsrf=2|0408e9fd|a78095c4f7b568288faa44494995fd64|1607876733; username-localhost-8888=\"2|1:0|10:1608040169|23:username-localhost-8888|44:MDMxZWQwYTRiM2FlNDg5YmJmYWY2NTA3MTQ2YWFhZGE=|c5d471ff1fa782b50cc2aae57301ac0c2af1cbb6ede9285ddb166ac49a50bc60\""], "Host": ["localhost:3000"], "Sec-Ch-Ua": ["\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\""], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/bye", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "localhost:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/bye", "protocol": "HTTP/1.1", "requestId": "b78f5472-bc99-442e-9e5b-e9383461b412", "requestTime": "25/Dec/2020:15:22:43 +0000", "requestTimeEpoch": 1608909763, "resourceId": "123456", "resourcePath": "/bye", "stage": "Prod"}, "resource": "/bye", "stageVariables": null, "version": "1.0"}
2020-12-25 16:22:46,437 | Found one Lambda function with name 'ByeLambdaFunction'
2020-12-25 16:22:46,437 | Invoking hello-lambda.core.ByeLambda (java8)
2020-12-25 16:22:46,437 | No environment variables found for function 'ByeLambdaFunction'
2020-12-25 16:22:46,438 | Environment variables overrides data is standard format
2020-12-25 16:22:46,438 | Loading AWS credentials from session with profile 'None'
2020-12-25 16:22:46,447 | Resolving code path. Cwd=/home/fierycod/Workspace/Personal/holy-lambda-master/examples/hello-lambda, CodeUri=target/output.jar
2020-12-25 16:22:46,447 | Resolved absolute path to code is /home/fierycod/Workspace/Personal/holy-lambda-master/examples/hello-lambda/target/output.jar
2020-12-25 16:22:46,448 | Decompressing /home/fierycod/Workspace/Personal/holy-lambda-master/examples/hello-lambda/target/output.jar
2020-12-25 16:22:46,469 | File META-INF/MANIFEST.MF in zipfile does not have permission information
2020-12-25 16:22:46,469 | File META-INF/maven/hello-lambda/hello-lambda/pom.xml in zipfile does not have permission information
2020-12-25 16:22:46,469 | File META-INF/leiningen/hello-lambda/hello-lambda/project.clj in zipfile does not have permission information
2020-12-25 16:22:46,469 | File META-INF/leiningen/hello-lambda/hello-lambda/README.md in zipfile does not have permission information
2020-12-25 16:22:46,469 | File fierycod/ in zipfile does not have permission information
2020-12-25 16:22:46,469 | File fierycod/holy_lambda/ in zipfile does not have permission information
2020-12-25 16:22:46,469 | File fierycod/holy_lambda/core$send_response.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/core$envs.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/core$fn__462.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/core$deflambda.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/core$ctx.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/core$loading__6721__auto____175.class in zipfile does not have permission information
2020-12-25 16:22:46,470 | File fierycod/holy_lambda/impl/ in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/util$fn__336.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/logging$warn.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/logging$fn__179.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/util$in__GT_edn_event.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/agent__init.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/agent$native_agents_files__GT_payloads_map.class in zipfile does not have permission information
2020-12-25 16:22:46,471 | File fierycod/holy_lambda/impl/util$success_code_QMARK_.class in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/agent$call_lambdas_with_agent_payloads.class in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/logging__init.class in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/util__init.class in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/util$call.class in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/logging/ in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/logging/proxy$java/ in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/logging/proxy$java/lang/ in zipfile does not have permission information
2020-12-25 16:22:46,472 | File fierycod/holy_lambda/impl/logging/proxy$java/lang/Object$LambdaLogger$eff0c8.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/util$http.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/agent$call_lambdas_with_agent_payloads$fn__364.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/logging$loading__6721__auto____177.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/agent$call_lambdas_with_agent_payloads$fn__367.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/logging$log.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/agent$native_agents_files__GT_payloads_map$fn__356.class in zipfile does not have permission information
2020-12-25 16:22:46,473 | File fierycod/holy_lambda/impl/logging$trace.class in zipfile does not have permission information
2020-12-25 16:22:46,474 | File fierycod/holy_lambda/impl/logging$info.class in zipfile does not have permission information
2020-12-25 16:22:46,474 | File fierycod/holy_lambda/impl/logging$error.class in zipfile does not have permission information
2020-12-25 16:22:46,474 | File fierycod/holy_lambda/impl/util$retrieve_body.class in zipfile does not have permission 
...
2020-12-25 16:22:47,086 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-java8:rapid-1.15.0.

2020-12-25 16:22:47,087 | Mounting /tmp/tmpu9372m39 as /var/task:ro,delegated inside runtime container
2020-12-25 16:22:47,560 | Starting a timer for 40 seconds for function 'ByeLambdaFunction'
2020-12-25 16:22:47,872 | Cleaning all decompressed code dirs
2020-12-25 16:22:47,957 | Invalid lambda response received: Lambda response must be valid json
2020-12-25 16:22:47 127.0.0.1 - - [25/Dec/2020 16:22:47] "GET /bye HTTP/1.1" 502 -
2020-12-25 16:22:48 127.0.0.1 - - [25/Dec/2020 16:22:48] "GET /favicon.ico HTTP/1.1" 403 -
2020-12-25 16:22:52,836 | Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'duration': 9595, 'exitReason': 'success', 'exitCode': 0, 'requestId': '93cd09f3-59d8-420b-ae31-bfa8ab97f365', 'installationId': '9e5be126-96c0-4976-a7b9-340378d2ed2c', 'sessionId': '244c10e6-7fbc-418e-93b9-98ed4ae19168', 'executionEnvironment': 'CLI', 'pyversion': '3.8.6', 'samcliVersion': '1.15.0'}}]}
2020-12-25 16:22:53,581 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Expected result:

It should work now as it was working a few months ago.

Additional environment details:

  1. OS: Linux x64 Pop!_OS 20.10
  2. sam --version: SAM CLI, version 1.15.0
moelasmar commented 3 years ago

I can reproduce this issue.

I was able to successfully run the same scenario using SAM CLI 1.12.0 -I need to check later versions-, but it is not working using version 1.15.0

I need to investigate more to know the reason of this issue.

moelasmar commented 3 years ago

The issue is that this bootstrap file is overwriting the new RAPID server bootstrap file. I was able to successfully running this scenario, by doing the following steps:

FieryCod commented 3 years ago

@moelasmar confirmed that your solution works! Thanks. Should I close the issue?

jeanabraham commented 3 years ago

@moelasmar I'm running into the same error of in zipfile does not have permission information when doing sam local invoke --env-vars json/env.json --docker-network host --debug, and I don't have a bootstrap file similar to the one list above. I'm running SAM CLI, version 1.21.1. Any ideas?

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      Handler: com.abc.Application::handleRequest
      Runtime: java8
      CodeUri: target/abc.jar