无法满足约束:成员必须满足正则表达式模式

问题描述 投票:0回答:1

我正在尝试遵循 spacy Universe 图层页面中的一个简单示例,但这对我来说失败了:

代码实现:

# template.yaml file

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  GetWordCounts:
    Type: AWS::Serverless::Function
    Properties:
      Handler: word-counts/app.lambda_handler
      Runtime: python3.9
      CodeUri: .
      Timeout: 30
      Layers:
        - arn:aws:lambda:${self:provider.region}:113088814899:layer:Klayers-python37-spacy:18
      Events:
        ApiGateway:
          Type: Api
          Properties:
            Path: /word-counts
            Method: get
# word-counts/app.py file

import json
import spacy

def lambda_handler(event, context):
    # Logic for Lambda function
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

我使用以下命令来启动 API:

sam local start-api --profile my-profile

因此,当我运行端点时,它失败并显示:

# http://localhost:3000/word-counts

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetLayerVersion operation: 1 validation error detected: Value 'arn:aws:lambda:${self:provider.region}:113088814899:layer:Klayers-python37-spacy' at
'layerName' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}:\d{12}:layer:[a-zA-Z0-9-_]+)|[a-zA-Z0-9-_]+

其他错误详细信息:

Mounting GetWordCounts at http://127.0.0.1:3000/word-counts [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local
commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template
2024-10-17 15:09:35 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:3000
2024-10-17 15:09:35 Press CTRL+C to quit
Invoking word-counts/app.lambda_handler (python3.9)
Exception on /word-counts [GET]
Traceback (most recent call last):
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/apigw/local_apigw_service.py", line 726, in _request_handler
    lambda_response = self._invoke_lambda_function(route.function_name, route_lambda_event)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/apigw/local_apigw_service.py", line 619, in _invoke_lambda_function
    self.lambda_runner.invoke(lambda_function_name, event_str, stdout=stdout_writer, stderr=self.stderr)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/commands/local/lib/local_lambda.py", line 166, in invoke
    self.local_runtime.invoke(
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/lib/telemetry/metric.py", line 325, in wrapped_func
    return_value = func(*args, **kwargs)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/lambdafn/runtime.py", line 224, in invoke
    container = self.create(
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/lambdafn/runtime.py", line 96, in create
    container = LambdaContainer(
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/docker/lambda_container.py", line 103, in __init__
    image = LambdaContainer._get_image(
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/docker/lambda_container.py", line 257, in _get_image
    return lambda_image.build(runtime, packagetype, image, layers, architecture, function_name=function_name)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/docker/lambda_image.py", line 201, in build
    downloaded_layers = self.layer_downloader.download_all(layers, self.force_image_build)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/layers/layer_downloader.py", line 77, in download_all
    layer_dirs.append(self.download(layer, force))
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/layers/layer_downloader.py", line 111, in download
    layer_zip_uri = self._fetch_layer_uri(layer)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/layers/layer_downloader.py", line 160, in _fetch_layer_uri
    raise e
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/samcli/local/layers/layer_downloader.py", line 141, in _fetch_layer_uri
    layer_version_response = self.lambda_client.get_layer_version(
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/botocore/client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/willian/.pyenv/versions/3.9.20/lib/python3.9/site-packages/botocore/client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetLayerVersion operation: 1 validation error detected: Value 'arn:aws:lambda:${self:provider.region}:113088814899:layer:Klayers-python37-spacy' at
'layerName' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}:\d{12}:layer:[a-zA-Z0-9-_]+)|[a-zA-Z0-9-_]+
2024-10-17 15:09:39 127.0.0.1 - - [17/Oct/2024 15:09:39] "GET /word-counts HTTP/1.1" 502 -
2024-10-17 15:09:39 127.0.0.1 - - [17/Oct/2024 15:09:39] "GET /favicon.ico HTTP/1.1" 403 -
python amazon-web-services aws-lambda spacy aws-lambda-layers
1个回答
0
投票

将图层更改为后我能够修复它:

      Layers:
        - arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-spacy:42
        - arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-spacy_model_en_small:1
© www.soinside.com 2019 - 2024. All rights reserved.