【发布时间】:2021-10-06 12:06:45
【问题描述】:
我在 VS Code 上有一个无服务器项目,安装了 Docker 桌面 4.10,但我不知道为什么上周五一切正常,因为周一我遇到了奇怪的错误,我无法弄清楚。我尝试更新 AWS CLI、Docker、VS 代码及其扩展,但没有任何进展。
这是我的 launch.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 "\var\runtime\dateutil\tz\win.py", line 13, in <module> (Current frame)
from six.moves import winreg
File "\var\runtime\dateutil\tz\tz.py", line 29, in <module>
from .win import tzwin, tzwinlocal
File "\var\runtime\dateutil\tz\__init__.py", line 2, in <module>
from .tz import *
File "\var\runtime\botocore\compat.py", line 27, in <module>
from dateutil.tz import tzlocal
File "\var\runtime\botocore\configloader.py", line 19, in <module>
from botocore.compat import six
File "\var\runtime\botocore\session.py", line 29, in <module>
import botocore.configloader
File "\var\runtime\boto3\session.py", line 17, in <module>
import botocore.session
File "\var\runtime\boto3\__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
【问题讨论】:
-
编辑:如果我调用“sam local invoke -t template.yaml -e event.json”,它工作得很好,但我没有调试器
标签: amazon-web-services image docker layer sam