serverless-localstack
serverless-localstack copied to clipboard
Error Attempting to Invoke Lambda Using Serverless
I created a simple test function, but when I attempt to invoke it using serverless, I get an error "Function not found: arn:aws:lambda:us-east-1:902088074489:function:localstack-test-local-hello".
I have a feeling that the invoke is actually attempting to invoke the function on AWS and not localstack.
localstack version: 0.9.1 serverless version: 1.44.1 serverless-localstack version: 0.4.15
I am running localstack via the command line.
$ localstack start
Starting local dev environment. CTRL-C to quit.
Starting mock SES (http port 4579)...
Starting mock CloudWatch Logs (http port 4586)...
Starting mock Redshift (http port 4577)...
Starting mock CloudFormation (http port 4581)...
Starting mock Firehose service (http port 4573)...
Starting mock Route53 (http port 4580)...
* Serving Flask app "firehose_api" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Starting mock ES service (http port 4578)...
Use a production WSGI server instead.
* Debug mode: off
* Serving Flask app "es_api" (lazy loading)
Starting mock IAM (http port 4593)...
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Starting mock DynamoDB Streams service (http port 4570)...
Starting mock S3 (http port 4572)...
* Serving Flask app "ddb_streams_api" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Starting mock CloudWatch (http port 4582)...
Use a production WSGI server instead.
* Debug mode: off
Starting mock DynamoDB (http port 4569)...
Starting mock Kinesis (http port 4568)...
Starting mock SQS (http port 4576)...
Starting mock SSM (http port 4583)...
Starting mock SNS (http port 4575)...
Starting mock API Gateway (http port 4567)...
Starting mock Secrets Manager (http port 4584)...
Starting local Elasticsearch (http port 4571)...
Starting mock STS (http port 4592)...
Starting mock StepFunctions (http port 4585)...
Starting mock Lambda service (http port 4574)...
* Serving Flask app "lambda_api" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Ready.
Then I deploy using serverless...
$ SLS_DEBUG=* AWS_PROFILE=kevin sls deploy -s local
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command deploy
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Using serverless-localstack
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:deploy:deploy
Serverless: [AWS cloudformation 400 0.037s 0 retries] describeStacks({ StackName: 'localstack-test-local' })
Serverless: Creating Stack...
Serverless: [AWS cloudformation 200 0.217s 0 retries] createStack({ StackName: 'localstack-test-local',
OnFailure: 'DELETE',
Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
Parameters: [ [length]: 0 ],
TemplateBody: '{"AWSTemplateFormatVersion":"2010-09-09","Description":"The AWS CloudFormation template for this Serverless application","Resources":{"ServerlessDeploymentBucket":{"Type":"AWS::S3::Bucket","Properties":{"BucketEncryption":{"ServerSideEncryptionConfiguration":[{"ServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}}}},"Outputs":{"ServerlessDeploymentBucketName":{"Value":{"Ref":"ServerlessDeploymentBucket"}}}}',
Tags: [ { Key: 'STAGE', Value: 'local' }, [length]: 1 ] })
Serverless: Checking Stack create progress...
Serverless: [AWS cloudformation 200 0.018s 0 retries] describeStackEvents({ StackName: 'arn:aws:cloudformation:us-east-1:123456789:stack/localstack-test-local/7be56736-5b24-4e24-b81d-8d75c90ab431' })
..
Serverless: Stack create finished...
Serverless: [AWS cloudformation 200 0.012s 0 retries] describeStackResource({ StackName: 'localstack-test-local',
LogicalResourceId: 'ServerlessDeploymentBucket' })
Serverless: [AWS s3 200 0.012s 0 retries] listObjectsV2({ Bucket: 'localstack-test-local-ServerlessDeploymentBucket-198106565693',
Prefix: 'serverless/localstack-test/local' })
Serverless: [AWS sts 200 0.02s 0 retries] getCallerIdentity({})
Serverless: Uploading CloudFormation file to S3...
Serverless: [AWS s3 200 0.012s 0 retries] putObject({ Body: <Buffer 7b 22 41 57 53 54 65 6d 70 6c 61 74 65 46 6f 72 6d 61 74 56 65 72 73 69 6f 6e 22 3a 22 32 30 31 30 2d 30 39 2d 30 39 22 2c 22 44 65 73 63 72 69 70 74 ... >,
Bucket: 'localstack-test-local-ServerlessDeploymentBucket-198106565693',
Key: 'serverless/localstack-test/local/1559580146081-2019-06-03T16:42:26.081Z/compiled-cloudformation-template.json',
ContentType: 'application/json',
Metadata: { filesha256: '1MRMtJWEicu14F9WcDfX++YzpoX0drzR3kS8rddlGJw=' } })
Serverless: Uploading artifacts...
Serverless: Uploading service localstack-test.zip file to S3 (3.97 KB)...
Serverless: [AWS s3 200 0.009s 0 retries] putObject({ Body: <Buffer 50 4b 03 04 14 00 08 00 08 00 00 00 21 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 69 6e 64 65 78 2e 6a 73 05 c1 31 0a 80 30 0c 05 d0 bd a7 c8 ... >,
Bucket: 'localstack-test-local-ServerlessDeploymentBucket-198106565693',
Key: 'serverless/localstack-test/local/1559580146081-2019-06-03T16:42:26.081Z/localstack-test.zip',
ContentType: 'application/zip',
Metadata: { filesha256: '6PjLP1P1qDCdmIUMY2jei5Spbhn6b8Q4Icx4E4EjtMU=' } })
Serverless: Validating template...
Serverless: Skipping template validation: Unsupported in Localstack
Serverless: Updating Stack...
Serverless: [AWS cloudformation 200 0.343s 0 retries] updateStack({ StackName: 'localstack-test-local',
Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
Parameters: [ [length]: 0 ],
TemplateURL: 'https://s3.amazonaws.com/localstack-test-local-ServerlessDeploymentBucket-198106565693/serverless/localstack-test/local/1559580146081-2019-06-03T16:42:26.081Z/compiled-cloudformation-template.json',
Tags: [ { Key: 'STAGE', Value: 'local' }, [length]: 1 ] })
Serverless: Checking Stack update progress...
Serverless: [AWS cloudformation 200 0.018s 0 retries] describeStackEvents({ StackName: 'arn:aws:cloudformation:us-east-1:123456789:stack/localstack-test-local/7be56736-5b24-4e24-b81d-8d75c90ab431' })
..
Serverless: Stack update finished...
Serverless: Invoke aws:info
Serverless: [AWS cloudformation 200 0.016s 0 retries] describeStacks({ StackName: 'localstack-test-local' })
Serverless: [AWS cloudformation 200 0.009s 0 retries] listStackResources({ StackName: 'localstack-test-local' })
Service Information
service: localstack-test
stage: local
region: us-east-1
stack: localstack-test-local
resources: 5
api keys:
None
endpoints:
None
functions:
hello: localstack-test-local-hello
layers:
None
Serverless: Invoke aws:deploy:finalize
Serverless: [AWS s3 200 0.042s 0 retries] listObjectsV2({ Bucket: 'localstack-test-local-ServerlessDeploymentBucket-198106565693',
Prefix: 'serverless/localstack-test/local' })
Serverless Enterprise: Run `serverless login` and deploy again to explore, monitor, secure your serverless project for free.Finally, I attempt to invoke using serverless...
$ SLS_DEBUG=* AWS_PROFILE=kevin sls invoke -s local -f hello
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command deploy
Serverless: Invoke invoke
Serverless: [AWS lambda 404 0.311s 0 retries] invoke({ FunctionName: 'localstack-test-local-hello',
InvocationType: 'RequestResponse',
LogType: 'None',
Payload: '***SensitiveInformation***' })
Serverless Error ---------------------------------------
Function not found: arn:aws:lambda:us-east-1:902088074489:function:localstack-test-local-hello
Stack Trace --------------------------------------------
ServerlessError: Function not found: arn:aws:lambda:us-east-1:902088074489:function:localstack-test-local-hello
at promise.catch.err (/usr/local/lib/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:302:11)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
OS: darwin
Node Version: 8.10.0
Serverless Version: 1.44.1
My serverless.yml...
service: localstack-test
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
plugins:
- serverless-localstack
custom:
localstack:
host: http://localhost
autostart: false
stages:
- local
lambda:
mountCode: false
functions:
hello:
handler: index.handler
I appreciate any help you can provide. Thanks!
This is still not working. But, I did find a workaround that does not use "serverless" invoke, but it would still be nice to get serverless invoke to work in the above example.
My workaround for now is to use the AWS SDK to invoke the functions deployed to localstack. However, I did have to change the command to start localstack to include LAMBDA_EXECUTOR.
$ LAMBDA_EXECUTOR=docker localstack start
I am having another problem now I will post in a new ticket.
As a side note, maybe a note about LAMBDA_EXECUTOR should be added to the main docs page for this repo. I ended up finding the solution in an issue comment.
Thanks!
Hi @kevinswarner , thanks for reporting. I just did a test with the sample you provided, and the lambda invocation using sls ... invoke ...worked for me. Can you please give it a try with the latest version?
closing old issue with no activity