我正在使用AWS CDK创建SAMCfnFunction
对于codeUri
属性,它需要引用一个^{
使用SAM CLI时,我可以执行以下操作
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
其中hello_world
有我函数的代码
运行sam build
和sam deploy
将代码打包并上载到S3,并在S3中使用正确的CodeUri
路径部署Cloudformation模板
我尝试使用CDK(Python)做类似的事情,但是samcli在幕后完成的工作没有发生
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
这个线程有点旧,但我遇到了这个问题,它是令人费解的,所以我想分享我的解决方案。通过使用
aws_s3_assets
库并将local
标志传递到无服务器堆栈中,以决定是否在synth上上载资产,或使用本地exec的路径,我能够解决部署中的这个问题例如:
我做了类似的事情,下面是我使用的方法
在template.yaml中
在package.json中
因此,当运行“npm run build”时,它将运行sam构建,并在cdk project/lambda/.aws sam下创建一个文件夹
在堆栈内部
相关问题 更多 >
编程相关推荐