gpt4 book ai didi

amazon-web-services - 从 CodeStar 项目自定义产品部署

转载 作者:行者123 更新时间:2023-12-03 07:35:39 25 4
gpt4 key购买 nike

我引用了这个文档:https://docs.aws.amazon.com/codestar/latest/userguide/customize-ec2-multi-endpoints.html#customize-ec2-multi-endpoints-newstage

我们目前有一个从“Java Spring,Web 服务”类型的 Beanstalk 模板创建的 CodeStar 项目。然而,使用 CloudFormation 生成的项目仅包含用于部署我们的 API 的单个环境。

问题:如何正确修改此模板,以便有两个不同的环境同时运行?

就 Beanstalk 而言:我们需要 SingleInstance输入我们的 dev实例,我们想要一个 LoadBalanced输入我们的 prod实例(使用两个 EC2 实例进行冗余)。

引用的教程提到awscodestar-<project_name>-infrastructure-prod用作 CloudFormation 集的堆栈名称,但是如果没有创建要部署的实际实例,那么它如何工作?我很困惑。

为什么还没有一个模板文件提供与所描述的类似的两个环境 CodePipeline/Beanstalk 设置?这似乎是一种相当主流的 CI/CD 方法。


这是我们的 template.yml文件:

AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::CodeStar

Conditions:
UseSubnet: !Not [!Equals [!Ref 'SubnetId', subnet-none]]

Parameters:
ProjectId:
Type: String
Description: AWS CodeStar project ID used to name project resources and create roles.
InstanceType:
Type: String
Description: The type of Amazon EC2 Linux instances that will be launched for this project.
KeyPairName:
Type: String
Description: The name of an existing Amazon EC2 key pair in the region where the project is created, which you can use to SSH into the new Amazon EC2 Linux instances.
VpcId:
Type: String
Description: The ID of the Amazon Virtual Private Cloud (VPC) used for the new Amazon EC2 Linux instances.
SubnetId:
Type: String
Description: The name of the VPC subnet used for the new Amazon EC2 Linux instances launched for this project.
SolutionStackName:
Type: String
Description: The software stack used to launch environments and configure instances in AWS Elastic Beanstalk.
EBTrustRole:
Type: String
Description: The service role in IAM for AWS Elastic Beanstalk to be created for this project.
EBInstanceProfile:
Type: String
Description: The IAM role that will be created for the Amazon EC2 Linux instances.
Stage:
Type: String
Description: The name for a project pipeline stage, such as Staging or Prod, for which resources are provisioned and deployed.
Default: ''
Resources:
EBApplication:
Description: The AWS Elastic Beanstalk application, which is a container used to deploy the correct application configuration.
Type: AWS::ElasticBeanstalk::Application
Properties:
ApplicationName: !Sub '${ProjectId}app${Stage}'
Description: The name of the AWS Elastic Beanstalk application to be created for this project.
EBApplicationVersion:
Description: The version of the AWS Elastic Beanstalk application to be created for this project.
Type: AWS::ElasticBeanstalk::ApplicationVersion
Properties:
ApplicationName: !Ref 'EBApplication'
Description: The application version number.
SourceBundle: 'target/ROOT'
EBConfigurationTemplate:
Description: The AWS Elastic Beanstalk configuration template to be created for this project, which defines configuration settings used to deploy different versions of an application.
Type: AWS::ElasticBeanstalk::ConfigurationTemplate
Properties:
ApplicationName: !Ref 'EBApplication'
Description: The name of the sample configuration template.
OptionSettings:
- Namespace: aws:elasticbeanstalk:environment
OptionName: EnvironmentType
Value: SingleInstance
- Namespace: aws:elasticbeanstalk:environment
OptionName: ServiceRole
Value: !Ref 'EBTrustRole'
- Namespace: aws:elasticbeanstalk:healthreporting:system
OptionName: SystemType
Value: enhanced
SolutionStackName: !Ref 'SolutionStackName'
EBEnvironment:
Description: The AWS Elastic Beanstalk deployment group where the application is deployed, which is made up of the Amazon EC2 Linux instances launched for this project.
Type: AWS::ElasticBeanstalk::Environment
Properties:
ApplicationName: !Ref 'EBApplication'
EnvironmentName: !Ref 'EBApplication'
Description: The application to be deployed to the environment.
TemplateName: !Ref 'EBConfigurationTemplate'
VersionLabel: !Ref 'EBApplicationVersion'
OptionSettings:
- Namespace: aws:autoscaling:launchconfiguration
OptionName: IamInstanceProfile
Value: !Ref 'EBInstanceProfile'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: InstanceType
Value: !Ref 'InstanceType'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: !Ref 'KeyPairName'
- Namespace: aws:ec2:vpc
OptionName: VPCId
Value: !Ref 'VpcId'
- !If
- UseSubnet
- Namespace: 'aws:ec2:vpc'
OptionName: Subnets
Value: !Ref 'SubnetId'
- !Ref "AWS::NoValue"

最佳答案

您可以创建一个主模板并将生产和开发模板作为嵌套堆栈引用。在这种情况下,您所要做的就是复制 template.yaml 文件两次,将副本重命名为适当的名称,然后将它们上传到 S3 存储桶。然后您的 template.yaml 文件将引用这两个模板。像这样的事情:

AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::CodeStar

Description: Master stack which creates all required nested stacks

Resources:
ProdStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: https://your-bucket/templates/production-stack.yml"
Parameters:
InstanceType: t2.micro
EBInstanceProfile: eg
KeyPairName: eg
VpcId: eg
ProjectId: eg
SubnetId: eg
SolutionStackName: eg
EBTrustRole: eg
Tags:
- Key: Environment
Value: Production
DevStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: https://your-bucket/templates/development-stack.yml"
Parameters:
InstanceType: t2.nano
EBInstanceProfile: eg
KeyPairName: eg
VpcId: eg
ProjectId: eg
SubnetId: eg
SolutionStackName: eg
EBTrustRole: eg
Tags:
- Key: Environment
Value: Dev

这将创建两个堆栈并允许您为每个堆栈输入适当的参数。看看这里:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html

您的管道可能会保留在主文件中,以及两个环境所需的任何其他参数,具体取决于您构建项目的方式。

关于amazon-web-services - 从 CodeStar 项目自定义产品部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60104575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com