Бессерверный с Localstack, не использующий S3 с локального хоста

Я использую бессерверный в сочетании с localstack и возникли проблемы с его работой.

Есть несколько запахов, из которых этот кажется мне наиболее подозрительным:

Serverless: Updating Stack...
Serverless: [AWS cloudformation 409 41.529s 1 retries] updateStack({
  StackName: 'hgcon-local',
  Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
  Parameters: [ [length]: 0 ],
  TemplateURL: 'https://s3.amazonaws.com/hgcon-local-serverlessdeploymentbucket-n7d45law4kmb/serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/compiled-cloudformation-template.json',
  Tags: [ { Key: 'STAGE', Value: 'local' }, [length]: 1 ]
})

Я ожидаю, что serverless запросит мой локальный S3, а не настоящий AWS. Когда я заменяю https://s3.amazonaws.com на http://localhost:4572/, я успешно вижу конфигурацию.

До этого вывода я получаю дополнительные предупреждения/ошибки, такие как:

Serverless Error ---------------------------------------

  ServerlessError: Role with name cf-hgcon-local-4ffca2574e47fb422239c0709aa320d2 already exists.
      at /home/cwill/Development/hh/hg-contact-service-playground/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:331:27
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-05-10T12:58:11:WARNING:localstack.services.cloudformation.cloudformation_starter: Unable to determine physical_resource_id for resource <class 'localstack.services.cloudformation.service_models.S3BucketPolicy'>
2020-05-10T12:58:17:WARNING:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:eu-central-1:000000000000:function:hgcon-local-contact-request-endpoint
2020-05-10T12:58:17:WARNING:localstack.services.awslambda.lambda_api: Function not found: arn:aws:lambda:eu-central-1:000000000000:function:hgcon-local-contact-request-endpoint
2020-05-10T12:58:17:ERROR:localstack.services.cloudformation.cloudformation_starter: Unable to parse and create resource "ContactDashrequestDashendpointLambdaFunction": expected string or bytes-like object Traceback (most recent call last):
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localhost:0/"

2020-05-10T12:30:47:WARNING:localstack.utils.cloudformation.template_deployer: Unexpected error retrieving details for resource IAM::Role: Could not connect to the endpoint URL: "http://localhost:0/" Traceback (most recent call last):
  File "/opt/code/localstack/.venv/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/opt/code/localstack/.venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/opt/code/localstack/.venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Я запускаю localstack через

DEFAULT_REGION=eu-central-1 SERVICES=s3,cloudformation,sns,lambda,sts,apigateway localstack start

и мое приложение с целью пряжи:

"start:local": "SLS_DEBUG=2 sls deploy -s local --profile local",

Это моя конфигурация локального стека в serverless.yml:

localstack:
    debug: true
    stages:
      - local
    host: http://localhost
    lambda:
      mountCode: true
    endpoints:
      S3: http://localhost:4572
      CloudFormation: http://localhost:4581
      SNS: http://localhost:4575
      Lambda: http://localhost:4574

Версии

node: 12.16.2
serverless: 1.68.0
localstack: 0.11.1

Вывод бессерверной консоли:

/home/cwill/.nvm/versions/node/v12.16.2/bin/node /home/cwill/.nvm/versions/node/v12.16.2/lib/node_modules/yarn/bin/yarn.js run start:local
yarn run v1.22.4
$ SLS_DEBUG=2 sls deploy -s local --profile local
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
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 upgrade
Serverless: Load command uninstall
Serverless: Load command webpack
Serverless: config.options_stage: local
Serverless: serverless.service.custom.stage: [object Object]
Serverless: serverless.service.provider.stage: ${self:custom.stage.${opt:branch, 'personal'}, opt:branch}
Serverless: config.stage: local
Serverless: Using serverless-localstack
Serverless: Reconfiguring service apigateway to use http://localhost:4567
Serverless: Reconfiguring service cloudformation to use http://localhost:4581
Serverless: Reconfiguring service cloudwatch to use http://localhost:4582
Serverless: Reconfiguring service lambda to use http://localhost:4574
Serverless: Reconfiguring service dynamodb to use http://localhost:4569
Serverless: Reconfiguring service kinesis to use http://localhost:4568
Serverless: Reconfiguring service route53 to use http://localhost:4580
Serverless: Reconfiguring service firehose to use http://localhost:4573
Serverless: Reconfiguring service stepfunctions to use http://localhost:4585
Serverless: Reconfiguring service es to use http://localhost:4578
Serverless: Reconfiguring service s3 to use http://localhost:4572
Serverless: Reconfiguring service ses to use http://localhost:4579
Serverless: Reconfiguring service sns to use http://localhost:4575
Serverless: Reconfiguring service sqs to use http://localhost:4576
Serverless: Reconfiguring service sts to use http://localhost:4592
Serverless: Reconfiguring service iam to use http://localhost:4593
Serverless: Reconfiguring service ssm to use http://localhost:4583
Serverless: Reconfiguring service rds to use http://localhost:4594
Serverless: Reconfiguring service ec2 to use http://localhost:4597
Serverless: Reconfiguring service elasticache to use http://localhost:4598
Serverless: Reconfiguring service kms to use http://localhost:4599
Serverless: Reconfiguring service secretsmanager to use http://localhost:4584
Serverless: Reconfiguring service logs to use http://localhost:4586
Serverless: Reconfiguring service cloudwatchlogs to use http://localhost:4586
Serverless: Reconfiguring service iot to use http://localhost:4589
Serverless: Reconfiguring service cognito-idp to use http://localhost:4590
Serverless: Reconfiguring service cognito-identity to use http://localhost:4591
Serverless: Reconfiguring service ecs to use http://localhost:4601
Serverless: Reconfiguring service eks to use http://localhost:4602
Serverless: Reconfiguring service xray to use http://localhost:4603
Serverless: Reconfiguring service appsync to use http://localhost:4605
Serverless: Reconfiguring service cloudfront to use http://localhost:4606
Serverless: Reconfiguring service athena to use http://localhost:4607
Serverless: Reconfiguring service S3 to use http://localhost:4572
Serverless: Reconfiguring service CloudFormation to use http://localhost:4581
Serverless: Reconfiguring service SNS to use http://localhost:4575
Serverless: Reconfiguring service Lambda to use http://localhost:4574
Serverless: Warning: Unable to find plugin named: TypeScriptPlugin
Serverless: Load command deploy
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command dev
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: config.options_stage: local
Serverless: serverless.service.custom.stage: [object Object]
Serverless: serverless.service.provider.stage: personal-cwill
Serverless: config.stage: local
Serverless: config.options_stage: local
Serverless: serverless.service.custom.stage: [object Object]
Serverless: serverless.service.provider.stage: personal-cwill
Serverless: config.stage: local
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Invoke webpack:validate
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Time: 10628ms
Built at: 05/10/2020 2:30:22 PM
                                  Asset     Size  Chunks                   Chunk Names
    src/api/contact-request-endpoint.js  218 KiB       0  [emitted]        src/api/contact-request-endpoint
src/api/contact-request-endpoint.js.map  690 KiB       0  [emitted] [dev]  src/api/contact-request-endpoint
Entrypoint src/api/contact-request-endpoint = src/api/contact-request-endpoint.js src/api/contact-request-endpoint.js.map
 [5] ./node_modules/http-errors/index.js 5.74 KiB {0} [built]
[16] ./src/api/contact-request-endpoint.ts 2.56 KiB {0} [built]
[17] ./src/mapper/contact-request-mapper.ts 355 bytes {0} [built]
[18] ./src/clients/listing-client.ts 909 bytes {0} [built]
[19] ./src/publisher/contact-request-publisher.ts 833 bytes {0} [built]
[20] ./config.ts 523 bytes {0} [built]
[21] external "aws-sdk" 42 bytes {0} [built]
[22] ./node_modules/@middy/core/index.js 7.55 KiB {0} [built]
[23] ./node_modules/@middy/core/isPromise.js 120 bytes {0} [built]
[24] ./node_modules/once/once.js 935 bytes {0} [built]
[26] ./node_modules/@middy/http-error-handler/index.js 650 bytes {0} [built]
[27] ./node_modules/@middy/http-json-body-parser/index.js 744 bytes {0} [built]
[40] ./node_modules/content-type/index.js 4.7 KiB {0} [built]
[41] ./node_modules/@middy/validator/index.js 2.71 KiB {0} [built]
[42] ./node_modules/ajv/lib/ajv.js 15.5 KiB {0} [built]
    + 105 hidden modules
Serverless: Invoke webpack:package
Serverless: Skip plugin function Package.packageService (lambda.mountCode flag is enabled)
Serverless: Skip plugin function AwsCompileFunctions.downloadPackageArtifacts (lambda.mountCode flag is enabled)
Serverless: Installing dependencies for custom CloudFormation resources...
Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Skip plugin function AwsDeploy.extendedValidate (lambda.mountCode flag is enabled)
Serverless: Invoke aws:deploy:deploy
Serverless: [AWS cloudformation 400 0.032s 0 retries] describeStacks({ StackName: 'hgcon-local' })
Serverless: Creating Stack...
Serverless: [AWS cloudformation 200 0.123s 0 retries] createStack({
  StackName: 'hgcon-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"}}]}}},"ServerlessDeploymentBucketPolicy":{"Type":"AWS::S3::BucketPolicy","Properties":{"Bucket":{"Ref":"ServerlessDeploymentBucket"},"PolicyDocument":{"Statement":[{"Action":"s3:*","Effect":"Deny","Principal":"*","Resource":[{"Fn::Join":["",["arn:",{"Ref":"AWS::Partition"},":s3:::",{"Ref":"ServerlessDeploymentBucket"},"/*"]]}],"Condition":{"Bool":{"aws:SecureTransport":false}}}]}}}},"Outputs":{"ServerlessDeploymentBucketName":{"Value":{"Ref":"ServerlessDeploymentBucket"}}}}',
  Tags: [ { Key: 'STAGE', Value: 'local' }, [length]: 1 ]
})
Serverless: Checking Stack create progress...
Serverless: [AWS cloudformation 200 0.038s 0 retries] describeStackEvents({
  StackName: 'arn:aws:cloudformation:eu-central-1:000000000000:stack/hgcon-local/94def164-0bf4-47ab-9626-427ae15d8698'
})
.
Serverless: Stack create finished...
Serverless: [AWS cloudformation 200 0.012s 0 retries] describeStackResource({
  StackName: 'hgcon-local',
  LogicalResourceId: 'ServerlessDeploymentBucket'
})
Serverless: [AWS s3 200 0.021s 0 retries] listObjectsV2({
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Prefix: 'serverless/hgcon/local'
})
Serverless: [AWS lambda 404 0.005s 0 retries] getFunction({ FunctionName: 'hgcon-local-contact-request-endpoint' })
Serverless: [AWS sts 200 0.01s 0 retries] getCallerIdentity({})
Serverless: Uploading CloudFormation file to S3...
Serverless: [AWS s3 200 0.013s 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 ... 6784 more bytes>,
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Key: 'serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/compiled-cloudformation-template.json',
  ContentType: 'application/json',
  Metadata: { filesha256: 'urjyxLvRyYb2wUh5A9h2T891BMKyfsl7jWr7lfC/slA=' }
})
Serverless: Skip plugin function AwsDeploy.uploadFunctionsAndLayers (lambda.mountCode flag is enabled)
Serverless: Uploading custom CloudFormation resources...
Serverless: [AWS s3 200 0.039s 0 retries] createMultipartUpload({
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Key: 'serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/custom-resources.zip',
  ContentType: 'application/zip',
  Metadata: { filesha256: 'ELtkm0Acuwt0UD/5r23Olk4qJ9AFFYsVUA1NBUFOif8=' }
})
Serverless: [AWS s3 200 0.03s 0 retries] uploadPart({
  Body: <Buffer f6 f6 43 9a dc 62 12 74 d7 34 48 87 5e e1 cc 1f 7f 54 19 18 65 23 47 df 11 fb 1a 58 cd 57 48 52 70 0e 53 80 d8 94 0e 5a 61 81 1d 25 c5 c3 39 4b 20 82 ... 1629151 more bytes>,
  ContentLength: 1629201,
  PartNumber: 2,
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Key: 'serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/custom-resources.zip',
  UploadId: '4QgDi64SpRWNMgk0gpGl3dGiPV111i8CAn8OZBlgRAcfYnV/TLV8IeVLZQ'
})
Serverless: [AWS s3 200 0.06s 0 retries] uploadPart({
  Body: <Buffer 50 4b 03 04 14 00 08 00 08 00 f5 66 a9 50 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 52 45 41 44 4d 45 2e 6d 64 8d cd c1 09 80 30 0c 46 e1 7b a7 ... 5242830 more bytes>,
  ContentLength: 5242880,
  PartNumber: 1,
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Key: 'serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/custom-resources.zip',
  UploadId: '4QgDi64SpRWNMgk0gpGl3dGiPV111i8CAn8OZBlgRAcfYnV/TLV8IeVLZQ'
})
Serverless: [AWS s3 200 0.025s 0 retries] completeMultipartUpload({
  MultipartUpload: {
    Parts: [
      { ETag: '"86af6ba7bce354c3737e2724eefcfd2d"', PartNumber: 1 },
      { ETag: '"6597702d089503065dfd77811585ea12"', PartNumber: 2 },
      [length]: 2
    ]
  },
  Bucket: 'hgcon-local-serverlessdeploymentbucket-n7d45law4kmb',
  Key: 'serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/custom-resources.zip',
  UploadId: '4QgDi64SpRWNMgk0gpGl3dGiPV111i8CAn8OZBlgRAcfYnV/TLV8IeVLZQ'
})
Serverless: Validating template...
Serverless: Skipping template validation: Unsupported in Localstack
Serverless: Updating Stack...
Serverless: [AWS cloudformation 409 41.529s 1 retries] updateStack({
  StackName: 'hgcon-local',
  Capabilities: [ 'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', [length]: 2 ],
  Parameters: [ [length]: 0 ],
  TemplateURL: 'https://s3.amazonaws.com/hgcon-local-serverlessdeploymentbucket-n7d45law4kmb/serverless/hgcon/local/1589113822319-2020-05-10T12:30:22.319Z/compiled-cloudformation-template.json',
  Tags: [ { Key: 'STAGE', Value: 'local' }, [length]: 1 ]
})

  Serverless Error ---------------------------------------

  ServerlessError: Role with name cf-hgcon-local-4ffca2574e47fb422239c0709aa320d2 already exists.
      at /home/cwill/Development/hg/hg-contact-service-playground/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:331:27
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.16.2
     Framework Version:         1.68.0
     Plugin Version:            3.6.6
     SDK Version:               2.3.0
     Components Version:        2.30.1

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 1

person Christopher Will    schedule 10.05.2020    source источник
comment
Я обнаружил, что stackoverflow.com/questions/59174365/, но это не помогло решить мои проблемы.   -  person Christopher Will    schedule 10.05.2020
comment
У меня сейчас именно эта проблема. Я не разрабатывал этот репозиторий более года, хотел обновить его после недавних изменений локального стека, которые раскрывают один пограничный порт 4566. Вы нашли решение? Я дам вам знать, если я что-нибудь найду   -  person Gavin van Gent    schedule 28.10.2020
comment
@GavinvanGent Нет, я отвернулся от локального стека.   -  person Christopher Will    schedule 29.10.2020
comment
Я смог заставить его работать после многих слез и пробивания лба экрана, но мне нужно пересмотреть код, чтобы выяснить, что на самом деле сработало после всех неудачных попыток ... Я думаю, это вам не поможет, но, может быть, следующий читатель   -  person Gavin van Gent    schedule 30.10.2020
comment
@GavinvanGent, ты смог понять, в чем проблема? Я столкнулся с той же проблемой   -  person Shiva Kishore    schedule 27.05.2021
comment
@ShivaKishore ты пришел правильно? Извиняюсь за задержку, я только что просмотрел свой код, чтобы попытаться найти что-то, что я сделал, чтобы исправить это, но для меня ничего не выделяется ... Если вы предоставите свою конфигурацию serverless.yml, я могу указать на различия с мой собственный и надеюсь найти решение для вас?   -  person Gavin van Gent    schedule 09.06.2021