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

Bug: sam local invoke - InvalidParameterValueException #7445

Open
nl-shawn-w opened this issue Sep 5, 2024 · 2 comments
Open

Bug: sam local invoke - InvalidParameterValueException #7445

nl-shawn-w opened this issue Sep 5, 2024 · 2 comments
Labels
area/local/invoke sam local invoke command blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@nl-shawn-w
Copy link

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.

        const paramsAndSecrets = ParamsAndSecretsLayerVersion.fromVersion(ParamsAndSecretsVersions.V1_0_103, {
            cacheSize: 500,
            logLevel: stage == STAGE.PROD ? ParamsAndSecretsLogLevel.INFO : ParamsAndSecretsLogLevel.DEBUG,
        });

        const handlerFunction =
            new PythonFunction(this, `${stackPrefix}-${handlerName}`, {
                runtime: Runtime.PYTHON_3_12,
                description: 'MY DESCRIPTION',
                entry: path.join(__dirname, '../../../src'),
                environment: {
                    STAGE: stage,
                    ...additionalEnv,
                },
                memorySize: 256,
                timeout: Duration.minutes(1),
                logRetention: RetentionDays.SIX_MONTHS,
                paramsAndSecrets,
            });

        mySecret.grantRead(handlerFunction);
cdk ls && sam local invoke -t cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/AWSSAapnortheast1devDeploymentStacksAWSSAapnortheast1devLambdaE3B5331D.template.json AWSSA-ap-northeast-1-dev-GithubBotHandler

Observed result:

2024-09-05 18:07:12,756 | No config file found in this directory.
2024-09-05 18:07:12,757 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/samconfig.toml'
2024-09-05 18:07:12,759 | Config file location:
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/samconfig.toml
2024-09-05 18:07:12,759 | Config file
'/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/samconfig.toml' does not exist
2024-09-05 18:07:12,776 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/samconfig.toml'
2024-09-05 18:07:12,777 | Using config file: samconfig.toml, config environment: default
2024-09-05 18:07:12,777 | Expand command line arguments to:
2024-09-05 18:07:12,778 |
--template_file=/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/AWSSAapnortheast
1devDeploymentStacksAWSSAapnortheast1devLambdaE3B5331D.template.json --function_logical_id=AWSSA-ap-northeast-1-dev-GithubBotHandler --no_event
--layer_cache_basedir=/Users/shawn.wang/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2024-09-05 18:07:12,778 | local invoke command is called
2024-09-05 18:07:13,937 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2024-09-05 18:07:13,966 | CDK Path for resource GithubBotHandlerRole78FCB05B is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'GithubBotHandlerRole', 'Resource']
2024-09-05 18:07:13,966 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerServiceRoleEA5D8DEB is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'ServiceRole', 'Resource']
2024-09-05 18:07:13,967 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerServiceRoleDefaultPolicyCAD33139 is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'ServiceRole', 'DefaultPolicy',
'Resource']
2024-09-05 18:07:13,967 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerD4138CC1 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'Resource']
2024-09-05 18:07:13,968 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerLogRetention7D632C49 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'LogRetention', 'Resource']
2024-09-05 18:07:13,968 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerFunctionUrl59783380 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'FunctionUrl', 'Resource']
2024-09-05 18:07:13,969 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerinvokefunctionurl4E059348 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'invoke-function-url']
2024-09-05 18:07:13,969 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'Resource']
2024-09-05 18:07:13,970 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole',
'DefaultPolicy', 'Resource']
2024-09-05 18:07:13,970 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'Resource']
2024-09-05 18:07:13,971 | CDK Path for resource CDKMetadata is ['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'CDKMetadata',
'Default']
2024-09-05 18:07:13,972 | Unable to resolve property Resource: [OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'}),
OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})].
Leaving as is.
2024-09-05 18:07:13,973 | Unable to resolve property Resource: OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'}). Leaving
as is.
2024-09-05 18:07:13,973 | Unable to resolve property GOOGLE_CREDS_SECRET_NAME: OrderedDict({'Fn::Join': ['-', [OrderedDict({'Fn::Select': [0,
OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'})]})]})]})]}),
OrderedDict({'Fn::Select': [1, OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'})]})]})]})]})]]
}). Leaving as is.
2024-09-05 18:07:13,975 | Unable to resolve property GOOGLE_CREDS_TOKEN_SECRET_NAME: OrderedDict({'Fn::Join': ['-', [OrderedDict({'Fn::Select': [0,
OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})]})]})]})
]}), OrderedDict({'Fn::Select': [1, OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':',
OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})]})]})]})
]})]]}). Leaving as is.
2024-09-05 18:07:13,976 | 0 stacks found in the template
2024-09-05 18:07:13,977 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2024-09-05 18:07:13,988 | CDK Path for resource GithubBotHandlerRole78FCB05B is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'GithubBotHandlerRole', 'Resource']
2024-09-05 18:07:13,989 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerServiceRoleEA5D8DEB is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'ServiceRole', 'Resource']
2024-09-05 18:07:13,989 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerServiceRoleDefaultPolicyCAD33139 is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'ServiceRole', 'DefaultPolicy',
'Resource']
2024-09-05 18:07:13,990 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerD4138CC1 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'Resource']
2024-09-05 18:07:13,990 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerLogRetention7D632C49 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'LogRetention', 'Resource']
2024-09-05 18:07:13,991 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerFunctionUrl59783380 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'FunctionUrl', 'Resource']
2024-09-05 18:07:13,991 | CDK Path for resource AWSSAapnortheast1devGithubBotHandlerinvokefunctionurl4E059348 is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'AWSSA-ap-northeast-1-dev-GithubBotHandler', 'invoke-function-url']
2024-09-05 18:07:13,992 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'Resource']
2024-09-05 18:07:13,992 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB is
['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole',
'DefaultPolicy', 'Resource']
2024-09-05 18:07:13,993 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A is ['AWSSA-ap-northeast-1-dev-DeploymentStacks',
'AWSSA-ap-northeast-1-dev-Lambda', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'Resource']
2024-09-05 18:07:13,993 | CDK Path for resource CDKMetadata is ['AWSSA-ap-northeast-1-dev-DeploymentStacks', 'AWSSA-ap-northeast-1-dev-Lambda', 'CDKMetadata',
'Default']
2024-09-05 18:07:13,994 | Unable to resolve property Resource: [OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'}),
OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})].
Leaving as is.
2024-09-05 18:07:13,995 | Unable to resolve property Resource: OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'}). Leaving
as is.
2024-09-05 18:07:13,995 | Unable to resolve property GOOGLE_CREDS_SECRET_NAME: OrderedDict({'Fn::Join': ['-', [OrderedDict({'Fn::Select': [0,
OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'})]})]})]})]}),
OrderedDict({'Fn::Select': [1, OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsB1803F6AAAECF8CB'})]})]})]})]})]]
}). Leaving as is.
2024-09-05 18:07:13,996 | Unable to resolve property GOOGLE_CREDS_TOKEN_SECRET_NAME: OrderedDict({'Fn::Join': ['-', [OrderedDict({'Fn::Select': [0,
OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':', OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})]})]})]})
]}), OrderedDict({'Fn::Select': [1, OrderedDict({'Fn::Split': ['-', OrderedDict({'Fn::Select': [6, OrderedDict({'Fn::Split': [':',
OrderedDict({'Fn::ImportValue':
'AWSSA-ap-northeast-1-dev-DeploymentStacks-AWSSA-ap-northeast-1-dev-Ssm:ExportsOutputRefAWSSAapnortheast1devGoogleCredentialsTokenEC2EA47A025BB956'})]})]})]})
]})]]}). Leaving as is.
2024-09-05 18:07:13,998 | 11 resources found in the stack
2024-09-05 18:07:13,998 | Found Lambda function with name='AWSSAapnortheast1devGithubBotHandlerD4138CC1' and
CodeUri='../asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7'
2024-09-05 18:07:13,999 | --base-dir is not presented, adjusting uri ../asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7 relative to
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/AWSSAapnortheast1devDeploymentSt
acksAWSSAapnortheast1devLambdaE3B5331D.template.json
2024-09-05 18:07:13,999 | Found Lambda function with name='LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A' and
CodeUri='../asset.4e26bf2d0a26f2097fb2b261f22bb51e3f6b4b52635777b1e54edbd8e2d58c35'
2024-09-05 18:07:14,000 | --base-dir is not presented, adjusting uri ../asset.4e26bf2d0a26f2097fb2b261f22bb51e3f6b4b52635777b1e54edbd8e2d58c35 relative to
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks/AWSSAapnortheast1devDeploymentSt
acksAWSSAapnortheast1devLambdaE3B5331D.template.json
2024-09-05 18:07:17,526 | Found one Lambda function with name 'AWSSA-ap-northeast-1-dev-GithubBotHandler'
2024-09-05 18:07:17,530 | Invoking index.handler (python3.12)
2024-09-05 18:07:17,531 | Loading AWS credentials from session with profile 'None'
2024-09-05 18:07:17,554 | Resolving code path.
Cwd=/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks,
CodeUri=/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7
2024-09-05 18:07:17,555 | Resolved absolute path to code is
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7
2024-09-05 18:07:17,556 | Resolving code path.
Cwd=/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/assembly-AWSSA-ap-northeast-1-dev-DeploymentStacks,
CodeUri=/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7
2024-09-05 18:07:17,556 | Resolved real code path to
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7
2024-09-05 18:07:17,557 | Code
/Users/shawn.wang/workspace/githubbot-workspace/AWSSAGithubBot/cdk/cdk.out/asset.4d4ad466218da20790b1de198a78464d8cae469b8a7089058fea7f63ca2881c7 is not a
zip/jar file
2024-09-05 18:07:18,918 | Cleaning all decompressed code dirs
2024-09-05 18:07:18,920 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-09-05 18:07:19,061 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-09-05 18:07:19,062 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '4c6d11ad-6dbe-4047-88e9-1d42647bd974', 'installationId':
'dff8abce-9c95-4d7e-9056-a0e79ae52de5', 'sessionId': 'b54fdba8-2c80-4b27-947f-2040d7923c76', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion':
'3.12.5', 'samcliVersion': '1.123.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke',
'metricSpecificAttributes': {'projectType': 'CDK', 'gitOrigin': None, 'projectName': 'afc607424cc02c92d4d6af5184a4fef46a69548e465a320808c6ff358b6a3a8d',
'initialCommit': None}, 'duration': 6142, 'exitReason': 'InvalidParameterValueException', 'exitCode': 255}}]}
2024-09-05 18:07:19,062 | Unable to find Click Context for getting session_id.
2024-09-05 18:07:19,065 | Sending Telemetry: {'metrics': [{'events': {'requestId': '7e0d1ceb-7b85-4ed0-8a04-2d26fecf6d5d', 'installationId':
'dff8abce-9c95-4d7e-9056-a0e79ae52de5', 'sessionId': 'b54fdba8-2c80-4b27-947f-2040d7923c76', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion':
'3.12.5', 'samcliVersion': '1.123.0', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension',
'event_value': '.toml', 'thread_id': '1509c4ab299441df81c2f827e5179eb2', 'time_stamp': '2024-09-05 10:07:12.758', 'exception_name': None}, {'event_name':
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '3ac4a099ce824791ac6faea43878f8c0', 'time_stamp': '2024-09-05 10:07:12.777', 'exception_name':
None}, {'event_name': 'UsedFeature', 'event_value': 'CDK', 'thread_id': '7950555c4e7c4fb69ed5348da6792320', 'time_stamp': '2024-09-05 10:07:18.923',
'exception_name': None}]}}}]}
2024-09-05 18:07:19,708 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2024-09-05 18:07:19,709 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Error: An error occurred (InvalidParameterValueException) when calling the GetLayerVersion operation: Invalid Layer name: arn:aws:lambda:ap-northeast-1:133490724326:layer:AWS-Parameters-and-Secrets-Lambda-Extension
Traceback:
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 185, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 150, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/lib/utils/version_checker.py", line 43, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/commands/local/invoke/cli.py", line 108, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/commands/local/invoke/cli.py", line 209, in do_cli
    context.local_lambda_runner.invoke(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/commands/local/lib/local_lambda.py", line 166, in invoke
    self.local_runtime.invoke(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 325, in wrapped_func
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/lambdafn/runtime.py", line 224, in invoke
    container = self.create(
                ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/lambdafn/runtime.py", line 96, in create
    container = LambdaContainer(
                ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/docker/lambda_container.py", line 103, in __init__
    image = LambdaContainer._get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/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 "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/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 "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/layers/layer_downloader.py", line 76, in download_all
    layer_dirs.append(self.download(layer, force))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/layers/layer_downloader.py", line 110, in download
    layer_zip_uri = self._fetch_layer_uri(layer)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/layers/layer_downloader.py", line 159, in _fetch_layer_uri
    raise e
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/samcli/local/layers/layer_downloader.py", line 140, in _fetch_layer_uri
    layer_version_response = self.lambda_client.get_layer_version(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.123.0/libexec/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)

An unexpected error was encountered while executing "sam local invoke".

Expected result:

Successfully ran Lambda

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

❯ sam --info
{
  "version": "1.123.0",
  "system": {
    "python": "3.12.5",
    "os": "macOS-14.5-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "27.0.3",
    "aws_cdk": "2.154.0 (build 0fc07f3)",
    "terraform": "1.9.3"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@nl-shawn-w nl-shawn-w added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 5, 2024
@hnnasit
Copy link
Contributor

hnnasit commented Sep 13, 2024

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!"}

@hnnasit hnnasit added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. area/local/invoke sam local invoke command and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Sep 13, 2024
@thorgefr
Copy link

thorgefr commented Oct 24, 2024

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
       

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

3 participants