首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SAM可以创建s3桶来存储lambda函数代码吗?

问SAM可以创建s3桶来存储lambda函数代码吗?
EN

Stack Overflow用户
提问于 2018-12-04 22:08:11
回答 1查看 2.7K关注 0票数 3

也许这不仅仅是一个问题。试着注册SAM Slack频道,但没有成功。

我正在尝试SAM来构建一个无服务器应用程序。我习惯于有一个Cloudformation模板来描述所需的所有资源。现在,我对为什么SAM的cli要求我传递s3桶到哪里上传lambda函数代码感到困惑。通常,我希望创建s3桶(随机名称)是Cloudformation执行的一部分。SAM是对Cloudformation的扩展,还是不对?

在我的template.yaml中,我有这样的东西:

代码语言:javascript
复制
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

如何在SrcBucket中引用CodeUri?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-04 22:29:57

不幸的是没有。

SAM模板的部署分为两部分,第一部分是package命令,它基本上是构造zip文件并需要一个s3桶才能将其上传到。还有deploy命令,它简单地部署打包的应用程序,就像cloudformation一样。

我通常有一个带有多个cloudformation的小型bash脚本,其中一个是助手堆栈,它创建这个桶(并在输出中添加名称),然后获取名称并将其传递给所有其他堆栈

代码语言:javascript
复制
#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 
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53622168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档