localstack / aws-sam-cli-local

Simple wrapper around AWS SAM CLI for use with LocalStack
Apache License 2.0
48 stars 8 forks source link

samlocal deployment of a lambda hanging #6

Open zopyx opened 1 year ago

zopyx commented 1 year ago

I am running localstack (1.0.0) locally and I am trying to deploy a lambda method (python) that I formerly tested with AWS.

The deployment using samlocal hangs:

samlocal deploy --no-confirm-changeset
File with same data already exists at salesforce-sync/398c2514884701a4dd22f62dbe18ac5f, skipping upload

    Deploying with following values
    ===============================
    Stack name                   : salesforce-sync
    Region                       : eu-central-1
    Confirm changeset            : False
    Disable rollback             : False
    Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-17ydsu5mgj77q
    Capabilities                 : ["CAPABILITY_IAM"]
    Parameter overrides          : {}
    Signing Profiles             : {}

Initiating deployment
=====================
File with same data already exists at salesforce-sync/cbe856eef7d4b8dbf0b6cf6ba0452961.template, skipping upload

Waiting for changeset to be created..
CloudFormation stack changeset
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation                                  LogicalResourceId                          ResourceType                               Replacement
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Modify                                   HelloWorldFunctionHelloWorldPermissionPr   AWS::Lambda::Permission                    False
                                           od
* Modify                                   HelloWorldFunctionRole                     AWS::IAM::Role                             False
* Modify                                   ServerlessRestApiProdStage                 AWS::ApiGateway::Stage                     False
* Modify                                   ServerlessRestApiDeployment47fc2d5f9d      AWS::ApiGateway::Deployment                False
* Modify                                   ServerlessRestApi                          AWS::ApiGateway::RestApi                   False
* Modify                                   HelloWorldFunction                         AWS::Lambda::Function                      False
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Changeset created successfully. arn:aws:cloudformation:eu-central-1:000000000000:changeSet/samcli-deploy1657786376/6e2dae38

2022-07-14 09:12:56 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 0.5 seconds)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                             ResourceType                               LogicalResourceId                          ResourceStatusReason
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 HelloWorldFunctionHelloWorldPermissionPr   -
                                                                                      od
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 HelloWorldFunctionRole                     -
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 ServerlessRestApiProdStage                 -
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 ServerlessRestApiDeployment47fc2d5f9d      -
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 ServerlessRestApi                          -
UPDATE_COMPLETE                            AWS::CloudFormation::Stack                 HelloWorldFunction                         -
CREATE_COMPLETE                            AWS::CloudFormation::Stack                 salesforce-sync                            -
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The localstack console shows:

2022-07-14T08:12:56.842  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeChangeSet => 200
2022-07-14T08:12:56.847  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS cloudformation.ExecuteChangeSet => 200
2022-07-14T08:12:56.894  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:12:57.160  INFO --- [  Thread-522] l.u.c.template_deployer    : Updating resource HelloWorldFunctionRole of type IAM::Role
2022-07-14T08:12:57.405  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:12:57.465  INFO --- [  Thread-522] l.u.c.template_deployer    : Updating resource HelloWorldFunction of type Lambda::Function
2022-07-14T08:12:57.927  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:12:58.469  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:12:59.001  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:12:59.524  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:00.059  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:00.583  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:01.116  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:01.654  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:02.191  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:02.721  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:03.241  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:03.759  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:04.277  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:04.809  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:05.328  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:05.843  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:06.362  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:06.893  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:07.436  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:07.959  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:08.492  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:09.012  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:09.533  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:10.060  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:10.599  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:11.137  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:11.654  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:12.181  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:12.702  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:13.229  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:13.750  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:14.284  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:14.815  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:15.331  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:15.859  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:16.382  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:16.915  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:17.437  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:17.963  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:18.482  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:19.014  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:19.532  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:20.046  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:20.559  INFO --- [   asgi_gw_7] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:21.072  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:21.596  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:22.124  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:22.652  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStackEvents => 200
2022-07-14T08:13:22.749  INFO --- [   asgi_gw_6] localstack.request.aws     : AWS cloudformation.DescribeStacks => 200
2022-07-14T08:13:52.789  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS cloudformation.DescribeStacks => 200
2022-07-14T08:14:22.833  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS cloudformation.DescribeStacks => 200
zopyx commented 1 year ago

Restarting localstack resolved the problem

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CloudFormation outputs from deployed stack
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key                 HelloWorldApi
Description         API Gateway endpoint URL for Prod stage for Hello World function
Value               https://0uw1iajmuo.execute-api.amazonaws.com:4566/Prod/hello/

Key                 HelloWorldFunction
Description         Hello World Lambda Function ARN
Value               arn:aws:lambda:eu-central-1:000000000000:function:salesforce-sync-HelloWorldFunction-afe360f4

Key                 HelloWorldFunctionIamRole
Description         Implicit IAM Role created for Hello World function
Value               arn:aws:iam::000000000000:role/salesforce-sync-HelloWorldFunctionRole-1fab8841
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Successfully created/updated stack - salesforce-sync in eu-central-1

However, the generated URL https://0uw1iajmuo.execute-api.amazonaws.com:4566/Prod/hello/ appears wrong...shouldn't that be something with localhost?

albehrens commented 1 year ago

Restarting localstack also means deleting your previous Cloudformation stacks. The reason why it works after restarting is because that Cloudformation stack does not exist. My deployments hang when they are updates of the existing stack (and so do yours). The updates are successful. The samlocal deploy just does not exit after Cloudformation emits the CREATE_COMPLETE.

dantabel commented 1 year ago

+1 I have the same issue. The app deploys fine the first time, subsequent deployments seem to be successful, but the console hangs at the end and doesn't exit forcing me to Ctrl+C.

Saymmic commented 8 months ago

The same in my case even for deploying in the new stack

xiaohk commented 5 months ago

The same in my case even for deploying in the new stack

Same issue here. How did you fix it?

I fixed this issue by making sure there is no any website / server calling the old stack APIs. For example, I had to kill my local server for a frontend website.

lakkeger commented 1 week ago

Hi @zopyx, Just checking if this issue had been resolved by the recently released 3.5.0 version which contains quite a few improvements on our CFn implementation and how it behaves during updates?