Home > OS >  AWS Lambda Application Layer
AWS Lambda Application Layer

Time:12-18

I'm trying to create a template.yml

index.js for layer

enter image description here

Layer in AWS Console

enter image description here

Zip of the layer

enter image description here

When I reference the layer from my other application I get the following build error.

enter image description here

template.yml for other application enter image description here

I am able to add the layer to the lambda through the aws console.

enter image description here

enter image description here

What's the correct way to reference this layer from the template.yml?

Update - debug output

sam local start-lambda --debug 2021-12-16 21:39:37,696 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2021-12-16 21:39:37,696 | Using config file: samconfig.toml, config environment: default 2021-12-16 21:39:37,696 | Expand command line arguments to: 2021-12-16 21:39:37,696 | --template_file=C:\Users\bensi\IdeaProjects\tu-record\template.yml --host=127.0.0.1 --port=3001 --layer_cache_basedir=C:\Users\bensi\ AppData\Roaming\AWS SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 2021-12-16 21:39:37,949 | local start_lambda command is called 2021-12-16 21:39:37,955 | Collected default values for parameters: {} 2021-12-16 21:39:37 Plugin 'ServerlessAppPlugin' raised an exception: 'list' object has no attribute 'get' Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\plugins_init_.py", line 133, in act getattr(plugin, method_name)(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\metrics\method_decorator.py", line 96, in wrapper_cw_timer exec_result = func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\plugins\application\serverless_app_plugin.py", line 92, in on_before_transfor m_template for logical_id, app in template.iterate({SamResourceType.Application.value}): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\sdk\template.py", line 33, in iterate resource = SamResource(resource_dict) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\sdk\resource.py", line 24, in init self.type = resource_dict.get("Type") AttributeError: 'list' object has no attribute 'get' 2021-12-16 21:39:37,973 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'd4aa74c5-a627-407e-8f65-f86fa97eeb15', 'installationId': 'e4cd6d85-622f -47df-8c87-08d5d6c395d6', 'sessionId': '80147f0f-42ce-4539-9edd-f08dd86eebcf', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion ': '1.36.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-lambda', 'duration': 277, 'exitReason': 'Att ributeError', 'exitCode': 255}}]} 2021-12-16 21:39:38,176 | Telemetry response: 200 Traceback (most recent call last): File "runpy.py", line 194, in _run_module_as_main File "runpy.py", line 87, in run_code File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli_main.py", line 12, in cli(prog_name="sam") File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in call return self.main(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main rv = self.invoke(ctx) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke return process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 157, in wrapped raise exception # pylint: disable=raising-bad-type File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 122, in wrapped File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\providers\sam_stack_provider.py", line 51, in init self.template_dict = self.get_template( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\providers\sam_base_provider.py", line 189, in get_template template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins() File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\samlib\wrapper.py", line 68, in run_plugins parser.parse(template_copy, all_plugins) # parse() will run all configured plugins File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\samlib\wrapper.py", line 88, in parse sam_plugins.act(LifeCycleEvents.before_transform_template, sam_template) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\plugins_init.py", line 139, in act raise ex File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\plugins_init.py", line 133, in act getattr(plugin, method_name)(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\metrics\method_decorator.py", line 96, in wrapper_cw_timer exec_result = func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\plugins\application\serverless_app_plugin.py", line 92, in on_before_transfor m_template for logical_id, app in template.iterate({SamResourceType.Application.value}): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\sdk\template.py", line 33, in iterate resource = SamResource(resource_dict) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samtranslator\sdk\resource.py", line 24, in init self.type = resource_dict.get("Type") AttributeError: 'list' object has no attribute 'get'

CodePudding user response:

Layer in your application template is expecting list Dictionary but its getting list because of - that could be the reason.[need to do more analysis]

Meanwhile, I suggest you use the below method to include the layer in your application

MyLayer:
  Type: AWS::Lambda::LayerVersion
  Properties:
    CompatibleRuntimes:
      - nodejs12.x
    Content:
      S3Bucket: <your-bucket-name>
      S3Key: layer.zip
    Description: My layer
    LayerName: my-layer
    LicenseInfo: MIT

CodePudding user response:

I needed to move the Layers: config in the template.yml under the lambda resource and replace $LATEST with a hardcoded reference to the version.

Resources:
  record:
    Type: AWS::Serverless::Function
    Properties:
      Layers:
        - arn:aws:lambda:us-east-2:501480421890:layer:testing-layers:7
  • Related