我正在使用AWS CDK创建SAM CfnFunction。
对于codeUri
属性,它需要引用S3LocationProperty
。
使用SAM CLI时,我可以做类似的事情
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
hello_world
包含我的函数的代码。
运行sam build
和sam 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?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。