Open nl-shawn-w opened 2 months ago
Hi @nl-shawn-w, I could not reproduce this on my side. I downloaded SAM CLI from here (not sure if this issue is coming from brew installed sam cli version). The error indicates the InvalidParameterValueException
failure from the downstream call to lambda.get_layer_version
, but arn:aws:lambda:ap-northeast-1:133490724326:layer:AWS-Parameters-and-Secrets-Lambda-Extension
looks correct to me.
Here's my project setup:
cdk-app.ts
import { Stack, StackProps } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { ParamsAndSecretsLayerVersion, ParamsAndSecretsLogLevel, ParamsAndSecretsVersions } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import path = require('path');
import * as sm from 'aws-cdk-lib/aws-secretsmanager';
import * as ssm from 'aws-cdk-lib/aws-ssm';
export class SamApp7445Stack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const secret = new sm.Secret(this, 'Secret');
const parameter = new ssm.StringParameter(this, 'Parameter', {
parameterName: 'mySsmParameterName',
stringValue: 'mySsmParameterValue',
});
const paramsAndSecrets = ParamsAndSecretsLayerVersion.fromVersion(ParamsAndSecretsVersions.V1_0_103, {
cacheSize: 500,
logLevel: ParamsAndSecretsLogLevel.INFO,
});
const lambdaFunction = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
handler: 'main.handler',
architecture: lambda.Architecture.ARM_64,
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
paramsAndSecrets,
});
secret.grantRead(lambdaFunction);
parameter.grantRead(lambdaFunction);
}
}
main.handler
def handler(event, context):
return {
'statusCode': 200,
'body': 'Hello from Lambda!'
}
Running cdk synth and then sam local invoke -t cdk.out/SamApp7445Stack.template.json MyFunction3BAA72D1
output
% sam local invoke -t cdk.out/SamApp7445Stack.template.json MyFunction3BAA72D1
Invoking main.handler (python3.12)
arn:aws:lambda:us-east-1:177933569100:layer:AWS-Parameters-and-Secrets-Lambda-Ex
tension-Arm64:4 is already cached. Skipping download
Local image is up-to-date
Using local image: samcli/lambda-python:3.12-arm64-d36d84289d99525b7fd33f891.
Mounting
/Users/hnnasit/Desktop/develop-workspace/sam-app-7445/cdk.out/asset.370a9c079319
8e3d55edef072b4d2ec8adf58aa7b201b49f623c34af6587d9fa as /var/task:ro,delegated,
inside runtime container
[AWS Parameters and Secrets Lambda Extension] 2024/09/13 17:59:09 PARAMETERS_SECRETS_EXTENSION_LOG_LEVEL is info. Log level set to info.
[AWS Parameters and Secrets Lambda Extension] 2024/09/13 17:59:09 INFO Systems Manager Parameter Store and Secrets Manager Lambda Extension 1.0.103
[AWS Parameters and Secrets Lambda Extension] 2024/09/13 17:59:09 INFO Serving on port 2773
[AWS Parameters and Secrets Lambda Extension] 2024/09/13 17:59:09 INFO ready to serve traffic
END RequestId: de9953b6-f037-4060-89a8-175c6f3f167b
REPORT RequestId: de9953b6-f037-4060-89a8-175c6f3f167b Init Duration: 0.04 ms Duration: 66.07 ms Billed Duration: 67 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"statusCode": 200, "body": "Hello from Lambda!"}
I have the same issue on mac with brew installed sam:
Error: An error occurred (InvalidParameterValueException) when calling the GetLayerVersion operation: Invalid Layer name: arn:aws:lambda:eu-central-1:XXXXXXX:layer:chromium-layer
Traceback:
File "click/core.py", line 1078, in main
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1434, in invoke
File "click/core.py", line 783, in invoke
File "samcli/cli/cli_config_file.py", line 347, in wrapper
File "click/decorators.py", line 92, in new_func
File "click/core.py", line 783, in invoke
File "samcli/lib/telemetry/metric.py", line 185, in wrapped
File "samcli/lib/telemetry/metric.py", line 150, in wrapped
File "samcli/lib/utils/version_checker.py", line 43, in wrapped
File "samcli/cli/main.py", line 95, in wrapper
File "samcli/commands/local/invoke/cli.py", line 108, in cli
File "samcli/commands/local/invoke/cli.py", line 209, in do_cli
File "samcli/commands/local/lib/local_lambda.py", line 166, in invoke
File "samcli/lib/telemetry/metric.py", line 325, in wrapped_func
File "samcli/local/lambdafn/runtime.py", line 224, in invoke
File "samcli/local/lambdafn/runtime.py", line 96, in create
File "samcli/local/docker/lambda_container.py", line 103, in __init__
File "samcli/local/docker/lambda_container.py", line 257, in _get_image
File "samcli/local/docker/lambda_image.py", line 201, in build
File "samcli/local/layers/layer_downloader.py", line 76, in download_all
File "samcli/local/layers/layer_downloader.py", line 110, in download
File "samcli/local/layers/layer_downloader.py", line 159, in _fetch_layer_uri
File "samcli/local/layers/layer_downloader.py", line 140, in _fetch_layer_uri
File "botocore/client.py", line 565, in _api_call
File "botocore/client.py", line 1017, in _make_api_call
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Scheduled Lambda function example
Resources:
ScheduledLambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: ScheduledLambdaFunction
Handler: handlers.main_handler.lambda_handler
Runtime: python3.9
CodeUri: ./
Description: A Lambda function that runs on a schedule
MemorySize: 1024
Timeout: 4800
PackageType: Zip
Layers:
- arn:aws:lambda:eu-central-1:XXXXXXX:layer:chromium-layer:2
- arn:aws:lambda:eu-central-1:XXXXXXX:layer:chromedriver-layer:2
- arn:aws:lambda:eu-central-1:XXXXXXX:layer:selenium-layer:2
Description:
SAM CLI unable to find an AWS-managed Lambda layer.
Steps to reproduce:
Create a Lambda with Param and Secrets Extension in CDK, and run Lambda locally with SAM CLI.
Observed result:
Expected result:
Successfully ran Lambda
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)