简体   繁体   English

如何使用AWS CodeDeploy和/或CloudFormation配置application.properties?

[英]How can I configure application.properties using AWS CodeDeploy and/or CloudFormation?

I have a Spring Web Service deployed on Elastic Beanstalk. 我在Elastic Beanstalk上部署了Spring Web Service。 I'm using AWS CloudFormation for the infrastructure and I'm using AWS CodePipeline to deploy the web service automatically from merges to the master branch. 我将AWS CloudFormation用于基础架构,并使用AWS CodePipeline将Web服务从合并自动部署到master分支。

Recently I added DynamoDB integration, and I need to configure a couple things in my application.properties. 最近,我添加了DynamoDB集成,并且需要在application.properties中配置一些内容。 I attempted to use environment variables to configure the application.properties but I hit a wall when trying to set the environment variables from CodeDeploy. 我尝试使用环境变量来配置application.properties,但是在尝试从CodeDeploy设置环境变量时遇到了麻烦。

This is my application.properties 这是我的application.properties

amazon.dynamodb.endpoint=${DYNAMODB_ENDPOINT:http://localhost:8000}
amazon.dynamodb.region=${AWS_REGION:default-region}
amazon.dynamodb.accesskey=${DYNAMODB_ACCESS_KEY:TestAccessKey}
amazon.dynamodb.secretkey=${DYNAMODB_SECRET_KEY:TestSecretKey}

spring.data.dynamodb.entity2ddl.auto = create-drop
spring.data.dynamodb.entity2ddl.gsiProjectionType = ALL
spring.data.dynamodb.entity2ddl.readCapacity = 10
spring.data.dynamodb.entity2ddl.writeCapacity = 1

The defaults are for when I'm running a local DynamoDB instance and they work fine. 默认值适用于当我运行本地DynamoDB实例时,它们可以正常工作。 However, I can't figure out how to get CodeDeploy to set environment variables for me, I also considered getting CloudFormation to set the environment variables, but couldn't find how to do that either. 但是,我不知道如何让CodeDeploy为我设置环境变量,我也考虑过让CloudFormation设置环境变量,但也找不到如何做到这一点。 I tried manually setting the environment variables in the EC2 instance but that didn't work and isn't the solution I'm looking for as I'm using EB and want this project to use fully automated deployments. 我尝试在EC2实例中手动设置环境变量,但这没有用,也不是我在使用EB时要寻找的解决方案,并且希望该项目使用全自动部署。 Please let me know if this is possible, what the industry standard is for configuring web services, and if I'm misunderstanding either CodeDeploy or CloudFormation. 请让我知道这是否可行,配置Web服务的行业标准是什么,以及是否误解了CodeDeploy或CloudFormation。

In general, it is a bad practice to include access and secret keys in any sort of files or in your deployment automation. 通常,将访问和密钥包含在任何类型的文件中或部署自动化中都是不好的做法。

Your instance that your application is deployed to should have an instance profile (ie IAM Role) attached to it which should have the appropriate DynamoDB permissions you need. 部署了应用程序的实例应附加一个实例配置文件(即IAM角色),该实例配置文件应具有所需的适当DynamoDB权限。

If you have that instance profile attached, the SDK should automatically be able to detect the credentials, region and endpoint is needs to communicate with. 如果您附加了该实例配置文件,则SDK应该能够自动检测与之通信的凭据,区域和端点。

You may need to update the way you are creating your DynamoDB client to just use the defaults. 您可能需要更新创建DynamoDB客户端的方式,以仅使用默认值。

To setup your development machine with these properties in a way that the AWS SDK can retrieve without explicitly putting them in properties files, you can run the aws configure command of the AWS CLI which should setup your ~/.aws/ folder with information about your region and credentials to use on your dev machine. 要将开发属性设置为具有这些属性的AWS开发工具,使AWS开发工具包可以检索这些属性而无需将它们显式放置到属性文件中,则可以运行AWS CLI的aws configure命令,该命令应在~/.aws/文件夹中设置有关您的信息您的开发机器上要使用的区域和凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用application.properties设置sessionFactory属性 - How Can I set sessionFactory properties using application.properties 如何更改 application.properties 中的属性? - How can i change properties in application.properties? 如何使用子gradle模块的application.properties? - How can I use application.properties of child gradle module? 如何以编程方式覆盖 Spring Boot application.properties? - How can I override Spring Boot application.properties programmatically? 如何更改我的application.properties文件? - How I can change my application.properties file? 如何使用 SpelExpressionParser 从 application.properties 获取值? - How can I get value from application.properties using SpelExpressionParser? "如何在 application.properties 文件中的 Spring Boot 应用程序中配置 HikariCP?" - How do I configure HikariCP in my Spring Boot app in my application.properties files? How can I map properties from spring application.properties to java object using lombok, when multiple dot(.) and hyphen(-) is there? - How can I map properties from spring application.properties to java object using lombok, when multiple dot(.) and hyphen(-) is there? 如何在application.properties文件中配置JMS侦听器 - How to configure JMS listener in application.properties file 如何配置Spring以从jar外部加载application.properties? - How to configure Spring to load application.properties from outside of jar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM