在Python中使用CDK中的CfnFunction在SAM中引用本地代码

我正在使用AWS CDK创建SAM CfnFunction

对于codeUri属性,它需要引用S3LocationProperty

使用SAM CLI时,我可以做类似的事情

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/

hello_world包含我的函数代码

运行sam buildsam deploy完成将代码打包和上传到S3的工作,并在S3中使用正确的CodeUri路径部署Cloudformation模板。

我尝试使用CDK(Python)做类似的事情,但是SAM cli进行的幕后工作并没有发生

from aws_cdk import (
    core,aws_sam as sam
)

class SamStack(core.Stack):
    
    def __init__(self,id,scope: core.Construct,**kwargs) -> None:
        super().__init__(id,scope,**kwargs)

        sam_stack = sam.CfnFunction(
            self,"MySamFunction",code_uri="lambda",# Directory with my code
            runtime="python3.8",handler="MyFunction.handler",# other properties removed
        )

使用创建堆栈时运行cdk deploy错误

Transform AWS::Serverless-2016-10-31 Failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [InferenceSam] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.

有没有办法使用CDK自动将python代码打包和上传到S3?

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...