spring-cloud-aws
spring-cloud-aws copied to clipboard
AWS Spring cloud map support (with AWS SDK v2)
Support for integrating with AWS Cloudmap
:loudspeaker: Type of change
- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
:scroll: Description
This pull request adds support for integrating spring boot application with AWS cloudmap. Here is an example of how an simple properties file integration looks like for both cloudmap registration and discovery
spring.cloud.aws.cloudmap.region=us-east-1
spring.cloud.aws.cloudmap.enabled=true
spring.application.name=cloudmap-namespace-here
# Discover existing cloudmap instances
spring.cloud.aws.cloudmap.discovery.failFast=false
spring.cloud.aws.cloudmap.discovery.discoveryList[0].service=TestService
spring.cloud.aws.cloudmap.discovery.discoveryList[0].nameSpace=ECS-CloudMap
# Register new instance
spring.cloud.aws.cloudmap.registry.description=Namespace for sample cloudmap registry service
spring.cloud.aws.cloudmap.registry.port=80
spring.cloud.aws.cloudmap.registry.service=a-service
spring.cloud.aws.cloudmap.registry.nameSpace=a-namespace
The property file is optional, any application can easily register themselves to cloudmap by adding spring-cloud-starter-aws-cloudmap
dependency to pom
or gradle
files, here is a example:
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws-cloudmap</artifactId>
</dependency>
:bulb: Motivation and Context
Adds support for cloudmap integration with spring boot applications for both service registry and discovery #5
:green_heart: How did you test it?
I executed the following tests:
- Ran unit test cases and made sure nothing failed
- Deployed the sample spring boot app checked in part of this pull request in ECS, EKS fargate instances. The application could successfully discover and register the application to AWS cloudmap.
:pencil: Checklist
- [x] I reviewed submitted code
- [x] I added tests to verify changes
- [x] I updated reference documentation to reflect the change
- [x] All tests passing
- [x] No breaking changes
:crystal_ball: Next steps
Code review and merging code to 3.x branch
Thanks @hariohmprasath. I'll do some polishing and very likely come back to you with some questions. In meantime, there are 3 things missing:
- reference documentation
- infrastructure for running a sample - or an instruction how to run the sample (I guess it's not possible to run it with Localstack)
- nullability annotations &
package-info.java
.
There are quite a few unused fields that I am not sure if just should be deleted or some parts of implementation is still missing.
Missing integration tests stopped me from doing further refactoring. If we can't test against Localstack, we should mock AWS API and perhaps use Wiremock to stub EC2/ECS endpoints.
I feel like the
CloudMapUtils
class is the center of this implementation and ideally we would refactor it to avoid having so much logic in the util class - but this can or even has to wait until we have integration tests so that we can refactor safely.@hariohmprasath would you be willing to address these issues? In case I am missing something, your opinion is appreciated.
Thanks for reviewing the code @maciejwalkowiak, let me start addressing some of the comments and we can sync up based on the changes
Reference documentation added, package-info with nullability annotation added, no infrastructure required if cloudmap namespace or service doesnt exist the cloudmap connector module will automatically create them
There are quite a few unused fields that I am not sure if just should be deleted or some parts of implementation is still missing. Missing integration tests stopped me from doing further refactoring. If we can't test against Localstack, we should mock AWS API and perhaps use Wiremock to stub EC2/ECS endpoints. I feel like the
CloudMapUtils
class is the center of this implementation and ideally we would refactor it to avoid having so much logic in the util class - but this can or even has to wait until we have integration tests so that we can refactor safely. @hariohmprasath would you be willing to address these issues? In case I am missing something, your opinion is appreciated.Thanks for reviewing the code @maciejwalkowiak, let me start addressing some of the comments and we can sync up based on the changes
@maciejwalkowiak, The last commit that I pushed in has code changes to mock the required HTTP responses. So we can use these tests as a reference for further refactoring. Since CloudMap is not supported in CloudMap
you may need to connect with AWS using credentials to run this sample.
It just requires the following environment variables to be set before running the sample application:
AWS_ACCESS_KEY_ID=<key>
AWS_REGION=us-east1
AWS_SECRET_ACCESS_KEY=<secret>
DEPLOYMENT_PLATFORM=ECS
Update CloudMapUtils.getEcsRegistrationAttributes()
, comment out line between 536 to 547 and return hard-coded ipAddress
and vpcId
, this is all you need to pretty much to run this sample.
@hariohmprasath thanks for an update. We still need to have an integration test that checks everything all together. Something like ParameterStoreConfigDataLoaderIntegrationTests
- does not need to use SpringApplication
, can just use Spring testing framework capabilities, but it has to give us confidence that when details change, the integration still works.
Considering it's not possible to use Localstack for that, either we need to mock responses from AWS or run the test against real AWS and spin up resources with Cloudformation. I can imagine this is quite a bit of work but we just cannot merge the integration lacking solid test coverage.
@hariohmprasath thanks for an update. We still need to have an integration test that checks everything all together. Something like
ParameterStoreConfigDataLoaderIntegrationTests
- does not need to useSpringApplication
, can just use Spring testing framework capabilities, but it has to give us confidence that when details change, the integration still works.Considering it's not possible to use Localstack for that, either we need to mock responses from AWS or run the test against real AWS and spin up resources with Cloudformation. I can imagine this is quite a bit of work but we just cannot merge the integration lacking solid test coverage.
Hi @maciejwalkowiak,
Thanks for reaching out to localstack
team regarding the support. I had a chance to catch up on their response and based on that I have submitted an enhancement (https://github.com/testcontainers/testcontainers-java/issues/5838) + PR (https://github.com/testcontainers/testcontainers-java/pull/5839) to support AWS CloudMap
for localstack
module in testcontainers
project.
Once the enhancement and PR gets approved I can use the same to add the required integration test cases. Hope this works for you, let me know your thoughts. Thanks
@hariohmprasath sounds like the way to go!
Hi @maciejwalkowiak,
I have added integration tests to test service discovery and registration for both the platforms (ECS
and EKS
).
-
EcsCloudMapIntegrationTest.java
- Integration tests forECS
platform -
EksCloudMapIntegrationTest.java
- Integration tests forEKS
platform
Note: Since
CloudMap
service is only enabled for pro version ofLocalStack
make sure to create an API Key (either using trial mode or buying a subscription), update the key inIntegrationTestUtil.LOCAL_STACK_API_KEY
variable before running the integration tests.
Hopefully this should make things easier for testing, let me know if you want me to update anything. Thanks and appreciate your support for this PR.
Hi @maciejwalkowiak, Just checking to see whether you had a chance to review the changes, let me know if you have any questions/suggestions. Thanks
@hariohmprasath not yet unfortunately but it's still high in my priority list so don't worry - it won't be ignored :-)
Hi @maciejwalkowiak, Hope you are doing great. Any tentative timeline when this support will be released? Thanks
@hariohmprasath apologies again, but we didn't find enough time to include it in 3.0.
3.0 will be released in April, CloudMap is planned for 3.1, so Q2/Q3 2023.
Sounds good, thanks for letting me know
Any updates to when this will be included?
Hi @maciejwalkowiak, Would love to get this merged by early 2024 :)
my first comment about license with localstack was wrong.. It seems by README and anecdotally in some issues, that there is a pro license for this project.
Just it doesn't seem used in CI not even on protected branches. For example, I would expect an env variable sourced from a repo or org secret. So, the impact is integration tests even when merged, won't run.. unless I'm missing somewhere else where they are run (should be in README somewhere about how the localstack creds are used)