我正在使用AWS CDK创建SAM CfnFunction。
对于codeUri
属性,它需要引用S3LocationProperty
。
使用SAM CLI时,我可以做类似的事情
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 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.