代码之家  ›  专栏  ›  技术社区  ›  TemporaryFix

aws sam发布/部署流程

  •  1
  • TemporaryFix  · 技术社区  · 6 年前

    我没有完全掌握用sam发布/部署的流程。我最大的问题是我的sam模板声明了一个 AWS::Serverless::Function

    我见过一些例子,其中CodeUri只是指向计算机上代码资源的路径。当我尝试这个的时候,山姆抱怨道

    为了避开这个我必须

    • 进入AWS控制台,删除我的s3 bucket中的资源,否则sam包不会上传
    • 运行sam包上传我的更新代码资源
    • 复制新的s3资源密钥
    • 回到我的模板,用新的s3 bucket uri替换CodeUri

    这真是令人讨厌。

    我错过了什么?

    { 
        "Description" : "Serverless backend",
        "Transform" : "AWS::Serverless-2016-10-31",
        "Globals" : {
        },
        "Resources" : {
            "db" : {
                "Type": "AWS::RDS::DBInstance",
                "Properties" : {
                    "AllocatedStorage": "20",
                    "DBInstanceClass": "db.t2.micro",
                    "DBName": "nameforthedb",
                    "DeleteAutomatedBackups": true,
                    "Engine": "postgres",
                    "MasterUsername": "masterUserName",
                    "MasterUserPassword": "******",
                    "PubliclyAccessible": true
                }
            },
            "signIn" : {
                "Type": "AWS::Serverless::Function",
                "Properties": {
                    "Handler": "index.signIn",
                    "Runtime": "nodejs8.10",
                    "CodeUri": "src", <--- complains when this is set to this. Code lives in the src folder. this is fine when I run sam package, but has to be changed to the s3 bucket when running sam deploy
                    "FunctionName": "signIn",
                    "Events": {
                        "SignIn" : {
                            "Type": "Api",
                            "Properties" : {
                                "Path" : "/signIn",
                                "Method" : "post"
                            }
                        }
                    }
                }
            },
            "Auth" : {
                "Type" : "AWS::Cognito::UserPool",
                "Properties": {
                    "Schema" : [
                        {
                            "AttributeDataType": "String",
                            "Name": "email",
                            "Mutable": true,
                            "Required": true
                        },
                        {
                            "AttributeDataType": "String",
                            "Name": "family_name",
                            "Mutable": true,
                            "Required": true
                        },
                        {
                            "AttributeDataType": "String",
                            "Name": "given_name",
                            "Mutable": true,
                            "Required": true
                        },
                        {
                            "AttributeDataType": "String",
                            "Name": "houseId",
                            "Mutable": true
                        },
                        {
                            "AttributeDataType": "Boolean",
                            "Name": "owner",
                            "Mutable": true
                        }
                    ],
                    "UsernameAttributes": ["email"]
                }
            }
        }
      }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   purple    5 年前

    TemporaryFix的评论是正确的答案。AWS SAM正确地将工件上传到s3,然后生成更新的模板文件。你呢 指定 --template-output-path packaged.yaml sam package --template-file packaged.yaml 运行 deploy command

    比如:

    
    sam build
    
    sam package --s3-bucket your-bucket --output-template-file packaged.yaml
    
    sam deploy --template-file packaged.yaml \
    --region eu-west-1 \
    --capabilities CAPABILITY_IAM \
    --stack-name your-stack
    
    
    
        2
  •  0
  •   KyleMit Steven Vachon    4 年前

    可以使用此工作流部署lambda函数

    1. 生成一个随机数。(类似于javauuid)也可以是git提交号

    2. 将工件上传到s3://your\u lmabda\u code\u bucket\u name/uuid

    3. CodeUri:
          Bucket: your_lmabda_code_bucket_name
          Key: !Sub '${uuid}/main.zip'
      
    4. 在部署期间将uri作为参数传递。

    推荐文章