VS Code 和 AWS SAM 本地调用问题



我在VS Code上有一个无服务器项目,安装了Docker桌面4.10,我不知道为什么上周五一切正常,因为周一我得到了奇怪的错误,我无法弄清楚。我尝试更新AWS CLI, Docker, VS code及其扩展,但没有进展。

这是我。json文件:

{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "lambda:index.handler (python3.8)",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/sam-utilites/template.yaml",
"logicalId": "Services2"
},
"sam": {
"containerBuild": true
},
"aws": {
"credentials": "profile:default"
},
"lambda": {
"runtime": "python3.8",
"payload": {
"path": "${workspaceFolder}/sam-utilites/events/update_item_name.json"
},
"environmentVariables": {
"TABLE_NAME": "Services2"
}
}
}
]
}

我得到了第一个错误:

Exception has occurred: ImportError       (note: full exception trace is shown but execution is paused at: <module>)
cannot import name 'winreg' from 'six.moves' (unknown location)
File "varruntimedateutiltzwin.py", line 13, in <module> (Current frame)
from six.moves import winreg
File "varruntimedateutiltztz.py", line 29, in <module>
from .win import tzwin, tzwinlocal
File "varruntimedateutiltz__init__.py", line 2, in <module>
from .tz import *
File "varruntimebotocorecompat.py", line 27, in <module>
from dateutil.tz import tzlocal
File "varruntimebotocoreconfigloader.py", line 19, in <module>
from botocore.compat import six
File "varruntimebotocoresession.py", line 29, in <module>
import botocore.configloader
File "varruntimeboto3session.py", line 17, in <module>
import botocore.session
File "varruntimeboto3__init__.py", line 16, in <module>
from boto3.session import Session

我认为Docker图像中有问题,或者在将层传递给Docker的模板文件中有问题。这是我的模板文件:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
AwsPowerToolsLayer:
Properties:
ContentUri: ../lambda-layers/aws-lambda-powertools
LayerName: AwsPowerToolsLayer
Type: AWS::Serverless::LayerVersion
ApiUtilities:
Properties:
ContentUri: ../lambda-layers/api-utilities
LayerName: ApiUtilities
Type: AWS::Serverless::LayerVersion
TokenUtilities:
Properties:
LayerName: TokenUtilities
ContentUri: ../lambda-layers/token-utilities
Type: AWS::Serverless::LayerVersion

Services2:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: python3.8
CodeUri: ../lambda
Description: ''
MemorySize: 128
Timeout: 300
Role: >-
arn:aws:iam::000000000000000:role/dev-0Service2ServiceRole4D3223-1MQZZZZZDEL6U
Events:
Api1:
Type: Api
Properties:
Path: /list
Method: GET
Environment:
Variables:
TABLE_NAME: tableName
Tags:
Environment: dev
Application: serviceApplication
Layers:
- !Ref AwsPowerToolsLayer
- !Ref ApiUtilities
- !Ref TokenUtilities

今晚遇到这个问题。

参见:https://github.com/aws/aws-sam-cli/issues/3347

在我的例子中,我检查了"未捕获的用户异常";在断点中。清除它修复了我的调试器!

最新更新