Closed antoniocaparros closed 2 years ago
Thanks for reporting @antoniocaparros . We haven't been able to reproduce this issue so far. Can you please share a minimal reproducible example?
Also, please make sure to do a docker pull localstack/localstack
to test with the latest version
Here's a repro that seems to be working:
$ touch handler.js
$ cat serverless.yml
service: lambda-test
frameworkVersion: "2"
plugins:
- serverless-localstack
custom:
localstack:
stages:
- local
package:
include:
- '**/**'
provider:
name: aws
region: us-east-1
runtime: nodejs12.x
functions:
SmartHomeCore:
handler: handler.handler
description: SmartHome Core - Manage every Core
events:
- http:
path: /core/{proxy+}
cors: true
method: ANY
private: false
authorizer:
type: COGNITO_USER_POOLS
name: SmartHomeAuthorizer
identitySource: method.request.header.X-API-Key
arn: arn:aws:cognito-idp:us-east-1:000000000:userpool/pool_id
- http:
path: /core/graphql
cors: true
method: ANY
private: false
- http:
path: /core/ping
method: GET
private: false
- http:
path: /core/docs
method: GET
private: false
iamRoleStatementsName: SmartHomeCoreRole
iamRoleStatements:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
- Effect: Allow
Action:
- s3:PutObject
Resource: "*"
- Effect: Allow
Action:
- iot:DeleteThing
- iot:CreatePolicy
Resource: "*"
layers:
- { Ref: MylayerLambdaLayer }
layers:
mylayer:
path: .
$ sls deploy --stage local
...
Serverless: Stack update finished...
...
Thanks!
Which extra info do You need?
@antoniocaparros Can you please share the version logs from your LocalStack container:
LocalStack version: 0.12.9.1
LocalStack Docker image id: 4b32cad49c25
LocalStack build date: 2021-04-22
LocalStack build git hash: b6203c02
Also, can you please share the full logs of your Docker container with - we may be able to reconstruct it from the DEBUG logs created by the CloudFormation deployment loop. Thanks for your help!
Hey everyone, I see its been a while since the last activity on this issue, but I have some interesting findings that may be helpful. I ran into a similar issue when creating a lambda via the AWS SDK for Java 2.x though the issue would happen only occasionally.
I think it's related to retries on the AWS client. My hypothesis is that the localstack container is taking too long to respond to the first request to create the lambda and then the AWS client is retrying the request, localstack is then responding to the retry with the ResourceConflictException
since it did actually create the lambda in the first request.
The AWS clients in the Java SDK seem to do 3 retries by default if nothing is configured based on these docs linked below (it sounds like it will use the "LEGACY" retry mode).
https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/retry/RetryMode.html
I was able to consistently recreate the issue by using a lambda client with the default retries and setting a really short timeout which will cause the client to retry the request to create the lambda.
LambdaClient client =
LambdaClient.builder()
// ... other overrides left out
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.apiCallAttemptTimeout(
Duration.ofMillis(100)) // Too short for localstack to respond in time
.build())
.build();
This consistently produces the ResourceConflictException
when you call createFunction
to make lambdas with this client.
software.amazon.awssdk.services.lambda.model.ResourceConflictException: Function already exist: FUNCTION_NAME_HERE (Service: Lambda, Status Code: 409, Request ID: null, Extended Request ID: null)
From that explanation it then follows that disabling the retries on the client should fix the issue.
LambdaClient client =
LambdaClient.builder()
// ... other overrides left out
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.retryPolicy(RetryPolicy.builder().numRetries(0).build())
.build())
.build();
I've tried this issue in my project and haven't seen the issue come back. Hopefully that helps your issue.
Type of request: This is a ...
[X] bug report
Detailed description
I am having problems deploying with serverless framework on my localstack. It is always getting this error:
I have checked before running this deploy that there aren't any resources created. My serverless.yml functions section:
My docker-compose.yml:
Steps to reproduce
Run docker container
TMPDIR=/private$TMPDIR docker-compose up
. Deploy using serverless frameworksls deploy --stage local --debug
.I am using plugin
serverless-localstack
for deployment