Unable to successfully deploy lambda with SAM

Hello.

I’m using a Pro trial. I created a new standalone lambda using sam init, and then tried to deploy using samlocal deploy --guided. In the console, the deploy reported all green. In the localstack logs, however, I see:

2022-09-19T15:31:36.885  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS cloudformation.DescribeStacks => 400 (ValidationError)
2022-09-19T15:31:36.896  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS cloudformation.DescribeStacks => 400 (ValidationError)
2022-09-19T15:31:36.921  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.HeadObject => 404 (404)
2022-09-19T15:31:37.001  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2022-09-19T15:31:37.026  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS cloudformation.DescribeStacks => 400 (ValidationError)
2022-09-19T15:31:37.057  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.HeadObject => 404 (404)
2022-09-19T15:31:37.081  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2022-09-19T15:31:37.106  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.GetObject => 200
2022-09-19T15:31:37.112  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS cloudformation.CreateChangeSet => 200
2022-09-19T15:31:37.124  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS cloudformation.DescribeChangeSet => 200
2022-09-19T15:31:37.142  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS cloudformation.DescribeChangeSet => 200
2022-09-19T15:31:41.574 DEBUG --- [   asgi_gw_1] l.s.c.provider             : Executing change set "arn:aws:cloudformation:us-west-2:000000000000:changeSet/samcli-deploy1663601497/b2369187" for stack "sam-app" with 1 resources ...
2022-09-19T15:31:41.575  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS cloudformation.ExecuteChangeSet => 200
2022-09-19T15:31:41.585  WARN --- [  Thread-305] l.u.c.template_deployer    : Unable to deploy resource type "Serverless::Function": {"Type": "AWS::Serverless::Function", "Metadata": {"SamResourceId": "helloFromLambdaFunction"}, "LogicalResourceId": "helloFromLambdaFunction", "Properties": {"Handler": "src/handlers/hello-from-lambda.helloFromLambdaHandler", "Runtime": "nodejs16.x", "Architectures": ["x86_64"], "MemorySize": 128, "Timeout": 100, "Description": "A Lambda function that returns a static string.", "Policies": ["AWSLambdaBasicExecutionRole"], "CodeUri": "s3://aws-sam-cli-managed-default-samclisourcebucket-edb2e12f/sam-app/ddaa0804d8ab800617e00e641a660143"}}
2022-09-19T15:31:41.585 DEBUG --- [  Thread-305] l.u.c.template_deployer    : Handling "Add" for resource "helloFromLambdaFunction" (1/1) type "AWS::Serverless::Function" in loop iteration 1 (should_deploy=False)
2022-09-19T15:31:42.096  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-09-19T15:31:42.120  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS cloudformation.DescribeStacks => 200
2022-09-19T15:31:42.132  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS cloudformation.DescribeStacks => 200

I’m not sure what those ValidationErrors are indicating - I haven’t changed the template from sam init. I’m also not sure what the Unable to deploy resource type means, other than the deploy didn’t work. On the console where I ran samlocal deploy --guided, everything is green:

Initiating deployment
=====================
Uploading to sam-app/5f8209bc4bef07d1ed5da963a0d898cd.template  728 / 728  (100.00%)

Waiting for changeset to be created..
CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                                LogicalResourceId                        ResourceType                             Replacement                            
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add                                    helloFromLambdaFunction                  AWS::Serverless::Function                N/A                                    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Changeset created successfully. arn:aws:cloudformation:us-west-2:000000000000:changeSet/samcli-deploy1663601497/b2369187


Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: y

2022-09-19 10:31:41 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 0.5 seconds)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                           ResourceType                             LogicalResourceId                        ResourceStatusReason                   
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_COMPLETE                          AWS::CloudFormation::Stack               helloFromLambdaFunction                  -                                      
CREATE_COMPLETE                          AWS::CloudFormation::Stack               sam-app                                  -                                      
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Successfully created/updated stack - sam-app in us-west-2

I’m not able to see the function from the CLI:

awslocal lambda list-functions
{
    "Functions": []
}

I’m working on a fresh install of localstack 1.1.0 on Debian 11. SAM CLI version 1.56.1. AWS CLI version 2.7.33 with Python 3.9.11. I started localstack via: START_WEB=1 LAMBDA_EXECUTOR=local DEFAULT_REGION=us-west-2 EAGER_SERVICE_LOADING=1 DEBUG=1 LOCALSTACK_API_KEY=mykey localstack start

Did I miss a step to be able to deploy lambdas?

Hi @semicolon , thanks for reporting. This could potentially be a region mismatch issue. From your logs, it definitely seems like the Lambda function has been created successfully - can you please double-check that the terminal where you’re running awslocal also targest the us-west-2 region:

AWS_DEFAULT_REGION=us-west-2 awslocal lambda list-functions

Hope that helps - please keep us posted… Thanks