Aws lambda SAM能否创建s3存储桶来存储lambda函数代码?
也许这不仅仅是一个问题。试图注册SAM Slack频道,但没有成功 我正在尝试SAM构建一个无服务器应用程序。我习惯于使用Cloudformation模板来描述所需的所有资源。现在我不明白为什么SAM的cli要求我将s3存储桶传递到上传lambda函数代码的位置。我通常希望创建s3 bucket(使用随机名称)是Cloudformation模板执行的一部分。SAM是云层形成的延伸吗 在我的Aws lambda SAM能否创建s3存储桶来存储lambda函数代码?,aws-lambda,amazon-cloudformation,aws-sam,aws-sam-cli,Aws Lambda,Amazon Cloudformation,Aws Sam,Aws Sam Cli,也许这不仅仅是一个问题。试图注册SAM Slack频道,但没有成功 我正在尝试SAM构建一个无服务器应用程序。我习惯于使用Cloudformation模板来描述所需的所有资源。现在我不明白为什么SAM的cli要求我将s3存储桶传递到上传lambda函数代码的位置。我通常希望创建s3 bucket(使用随机名称)是Cloudformation模板执行的一部分。SAM是云层形成的延伸吗 在我的template.yaml中,我有如下内容: Resources: SrcBucket: Ty
template.yaml
中,我有如下内容:
Resources:
SrcBucket:
Type: AWS::S3::Bucket
MyFunction:
Type: AWS::Serverless::Function
Properties:
Timeout: 3
Runtime: python3.7
Handler: my.lambda_handler
CodeUri: my/
Events:
ShopifyInstall:
Type: Api
Properties:
Path: /
Method: get
如何在CodeUri中引用SrcBucket?很遗憾,没有
SAM模板的部署分为两部分:第一部分是package命令,它基本上构造了zip文件,需要一个s3 bucket将其上传到。
还有deploy命令,它只是像cloudformation一样部署打包的应用程序
我通常有一个带有多个cloudformation堆栈的小bash脚本,其中一个是helper堆栈,它创建这个bucket(并在输出中添加名称),然后获取名称并将其传递给所有其他堆栈
#Create the Helper stack
echo "---------Create Helper stack ---------"
aws cloudformation deploy --profile ${profile} --stack-name $helperStack --
region ${region} --template-file deployment-helper.yaml
serverlessCodeBucketName="$(aws cloudformation --region ${region} --profile
${profile} describe-stacks --stack-name $helperStack --query
'Stacks[0].Outputs[?OutputKey==`CodeBucketName`].OutputValue' --output text)"
aws cloudformation package --profile ${profile} --region ${region} --
template-file template.yaml --output -
template-file serverless-output.yaml --s3-bucket
${serverlessCodeBucketName}
aws cloudformation deploy --profile ${profile} --stack-name
${applicationStack} --region ${region} --template-file
serverless-output.yaml --capabilities
CAPABILITY_IAM
非常感谢。最后我和ansible一起做了。