aws / aws/aws-toolkit-vscode

Invalid SamLaunchRequestError for lambda runtime.

Open
#3,161 3 comments 0 reactions 0 assignees View on GitHub
bug needs-response sam
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## Problem
I am seeing an error upon launching an "aws-sam" type direct-invoke of a lambda function based on on nodejs:

> *2023-02-11 01:51:36 [ERROR]: SamLaunchRequestError: Invalid launch configuration: Runtime for Template Resource LambdaFunction in Template file C:\whennemuth\workspaces\bu_workspace\bu-wp-assets-olap\template.yaml is either undefined or unsupported. [BadLaunchConfig]*

What this error seems to be reporting is not true, the runtime, nodejs16.x is neither undefined or unsupported.

My launch configuration is as follows:

```
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "LAMBDA",
"aws": {
"credentials": "profile:infnprd",
"region": "us-east-1"
},
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "LambdaFunction"
},
"lambda": {
"runtime": "nodejs16.x",
"payload": {
"path": "events/event.json"
},
"environmentVariables": {
"S3_BUCKET": "bu-wp-assets-olap-dev-assets",
"S3_REGION": "us-east-1",
"HOST_NAME": "3.215.250.187",
"SHIBBOLETH": "true"
}
}
}
```

The lambda function in template.yaml is:

```
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-s3-proxy
Description: Receives https originated requests for s3 content and conditionally returns after applying authorization logic.
Runtime: nodejs16.x
Architectures: [ x86_64 ]
CodeUri: ./
Handler: src/Handler.GetAsset
Timeout: 60
Environment:
Variables:
S3_REGION: !Ref AWS::Region
S3_BUCKET: !Ref Bucket
SHIBBOLETH: !Ref Shibboleth
HOST_NAME:
!If
- CustomHostName
- !Ref HostName
- !If
- IncludeEIP
- !GetAtt EC2EIP.PublicIp
- !If
- IncludeEC2
- "lookup"
- "local-ol"
Policies:
- S3CrudPolicy:
BucketName: !Ref Bucket
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:*
Resource:
- !GetAtt LambdaLogsGroup.Arn
- Effect: Allow
Action:
s3-object-lambda:WriteGetObjectResponse
Resource:
'*'
```

## Steps to reproduce the issue

1. Start a sam project in vscode

2. Put the lambda content above in a file named template.yaml in the top level directory.

3. Put the launch configuration above in the .vscode directory

4. Create a file ./src/Handler.js:

```
exports.GetAsset = async function(event, context) {
console.log('hello');
}
```

5. Put a breakpoint on the line that prints "hello" and try to launch the "LAMBDA" configuration.

6. This will work the first time, and you will see execution pause on the breakpoint.

7. Terminate the debug session *(do not let it run its course)*

8. Repeat step 5 and you should see the error.

9. The only way to clear the error is to close vscode and reopen.

I'm not sure if this can be repeatable for you since I suspect it may have something to do with my specific system details *(see below)*.
However, I'd appreciate some clues as to how to get it to stop or an alternative approach that may bypass any suspected issues.

## Expected behavior

No such error is expected - "nodejs16.x" should be accepted.

## System details:

- OS: Windows_NT x64 10.0.19045
- Visual Studio Code extension host: 1.75.0
- AWS Toolkit: 1.62.0
- node: 16.14.2
- electron: 19.1.9

Contributor guide

Open the contributing guide

Research direction

Reproduce the repeated direct-invoke launch using the .vscode launch configuration, template.yaml, and src/Handler.js with the AWS Toolkit in VS Code. Compare the first successful run with a session terminated before completion, then verify that relaunching the same LAMBDA configuration accepts nodejs16.x without restarting VS Code.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nodejs, typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.