Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HELP] Failed to satisfy constraint: Member must satisfy regular expression pattern #447

Closed
willianfalbo opened this issue Oct 17, 2024 · 1 comment

Comments

@willianfalbo
Copy link

Hey guys, could you help me with this question?

I'm trying to follow a simple example from spacy universe layers page, but this is failing for me:

Code Implementation:

# 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!')
    }

I'm using the following command to launch the API:

sam local start-api --profile my-profile

So when I run the endpoint, it fails with:

# 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-_]+

Additional error details:

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 -
@willianfalbo
Copy link
Author

I was able to fix it after changing the layers to:

      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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant