微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AWS Toolkit for VS 2019 在运行时删除数据库实例?

如何解决AWS Toolkit for VS 2019 在运行时删除数据库实例?

我正在使用 AWS Toolkit for VS 2019 并且我正在尝试部署一个新的无服务器应用程序。我使用 CLI 和 serverless.template 文件部署新数据库,如下所示:

  "AWstemplateFormatVersion": "2010-09-09","Transform": "AWS::Serverless-2016-10-31","Description": "Testing AWS setup in Visual Studio.","Resources": {
        "ConfigBucket" : {
            "Type" : "AWS::S3::Bucket","Properties" : {
                "BucketName" : "a-test-bucket"
            }
        },"Database" : {
            "Type" : "AWS::RDS::DBInstance","Properties" : {
                "DBInstanceClass" : "db.t2.micro","EngineVersion": "14.00.3294.2.v1","AllocatedStorage" : "20","Engine" : "sqlserver-ex","PubliclyAccessible" : true,"MasterUsername" : "myUsername","MasterUserPassword" : "myPassword"
            }
        }
  }

}

使用 CLI 命令:aws cloudformation deploy --template-file serverless.template --stack-name LBTServerlessApp

数据库实例创建良好,然后我可以在 MSSMS 中访问以将数据和 SP 部署到其中。

然后我尝试使用以下 serverless.template 文件从我的第二个项目部署 Lambda:

{
  "AWstemplateFormatVersion": "2010-09-09","Description": "An AWS Serverless Application.","Resources": {
    "Get": {
      "Type": "AWS::Serverless::Function","Properties": {
        "Handler": "LBTServerlessAppTest::LBTServerlessAppTest.GetUsersFunction::GetUser","Runtime": "dotnetcore3.1","CodeUri": "","MemorySize": 256,"Timeout": 30,"Role": null,"Policies": [
          "AWSLambdaBasicExecutionRole"
        ],"Events": {
          "RootGet": {
            "Type": "Api","Properties": {
              "Path": "/GetUser","Method": "GET"
            }
          }
        }
      }
    }
  },"Outputs": {
    "ApiURL": {
      "Description": "API endpoint URL for DEV environment","Value": {
        "Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/DEV/"
      }
    }
  }
}

和 aws-lambda-tools-defaults.json 文件


{
    "information" : [
        "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.","To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.","dotnet lambda help","All the command line options for the Lambda command can be specified in this file."
    ],"profile"     : "default","region"      : "eu-west-2","configuration" : "Release","framework"     : "netcoreapp3.1","s3-prefix"     : "LBTServerlessApp/","template"      : "serverless.template","template-parameters" : "","s3-bucket"           : "a-test-bucket","stack-name"          : "LBTServerlessApp"
}

使用 CLI 命令:dotnet lambda deploy-serverless -cfg aws-lambda-tools-defaults.json -pcfg true(也可以通过右键单击 + 发布到 AWS Lambda 获得相同的结果)

两者都部署到相同的 Cloud Formation 堆栈和相同的存储桶。正在创建 Lambda 和 API 端点,但是,第二次部署删除数据库和存储桶!所以我只剩下 API Gateway 端点和 Lamdba,但没有数据库来运行调用!?我已经尝试了 IO 可以想到的所有内容包括存储桶版本控制,但数据库总是被删除。任何人都可以解释为什么会发生这种情况吗?

解决方法

小学生错误!我在两个 serverless.template 文件中命名堆栈名称相同。为了使其工作,您需要 2 个独立的 Cloud Formation 堆栈。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?