Reputation: 469
So I'm trying to convert an existing spring boot application to an AWS lambda and using SAM.
I'm trying to use aws-sam-cli to try my lambda locally, however with my SAM setup I am getting: Template does not have any APIs connected to Lambda functions
When I do: sam local start-api
My template.yml
:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: foo
Resources:
MailFunction:
Type: AWS::Serverless::Function
Properties:
Handler: bar.LambdaHandler::handleRequest
Runtime: java8
CodeUri: target/foo-bar-1.0.jar
Timeout: 300
MemorySize: 1024
Events:
Timer:
Type: Schedule
Properties:
Schedule: rate(1 day)
Any idea what I'm doing wrong? It looks correct as far as I can tell from https://blog.couchbase.com/aws-serverless-lambda-scheduled-events-tweets-couchbase/ + https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html
Upvotes: 19
Views: 14857
Reputation: 5818
For Googlers:
Event
with Type: Api
sam build
(very important)--debug
flag so you will know what is going onAs of 2020/7/13, Type: HttpApi
does not work with sam local start-api
. See issue.
Upvotes: 14
Reputation: 653
I am getting this error, but I have function that is working with the HttpApi
, it appears that current version of sam
does not support HttpApi
.
CLI Version
SAM CLI, version 0.52.0
Example Function
FeedsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri:
Description: "Function that handles feeds"
Events:
Handler:
Type: HttpApi
Properties:
ApiId: !Ref FeedsApi
Path: /
Method: get
Handler: api
MemorySize: 1024
Runtime: go1.x
Timeout: 5
Tracing: Active
There is currently an open issue on GitHub for adding support: https://github.com/awslabs/aws-sam-cli/issues/1641
Upvotes: 1
Reputation: 1506
This error message also displays if you are trying to test a websocket API locally. Unfortunately, local testing of websockets is not currently supported - see https://github.com/awslabs/aws-sam-cli/issues/896.
Upvotes: 3
Reputation: 6003
I got this error when I had a whitespace error in my AWS::Serverless::Function definition, specifically Environment
needed to be a child of Properties
but was on the same level. Correcting the whitespace made this error disappear. Nodejs 10.15.
Upvotes: 0
Reputation: 17771
I ran into this error too even when I did have an Api
event defined in my SAM template. The problem was that I had a previous template in my .aws-sam/build/
directory which didn't have the Api event defined (from a previous run of sam build
). Cleaning out the build directory fixed it.
Upvotes: 2
Reputation: 32808
You didn't add any API Gateway event to your function. And start-api
spawn a local API Gateway.
You need to add at least one Api
event to your Events
section.
Events:
[...]
Api:
Type: Api
Properties:
Path: /myresource
Method: get
If you just have a Schedule
event, try to use generate-event
to create such an event.
sam local generate-event schedule ...
and invoke function e.g. sam local invoke function-name -e event_file.json
(see)
Upvotes: 20