【发布时间】:2020-12-04 10:15:50
【问题描述】:
我正在使用 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?
【问题讨论】:
标签: python amazon-web-services amazon-cloudformation aws-cdk aws-sam