我正在使用无服务器版本 1.29.2
我创建了一个初始 cloudformation 脚本,该脚本创建了一个将由其他服务使用的 API GateWay REST API。所以这是负责它的 cloudformation 脚本。
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"API",
"Resources":{
"APIGw":{
"Type":"AWS::ApiGateway::RestApi",
"Properties":{
"Name":"API-GW"
}
}
},
"Outputs":{
"ApiGwRestApiId":{
"Value":{
"Ref":"APIGw"
},
"Export":{
"Name":"apigw-restApiId"
}
},
"eyesApiGwRestApiRootResourceId":{
"Value":{
"Fn::GetAtt":[
"APIGw",
"RootResourceId"
]
},
"Export":{
"Name":"apigw-rootResourceId"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试部署的应用程序的 serverless.yml。
service: template-test-service
provider:
name: aws
runtime: python3.6
region: eu-central-1
stage: ${self:custom.environment.stage}
environment:
stage: ${self:custom.environment.stage}
apiGateway:
restApiId:
'Fn::ImportValue': apigw-restApiId
restApiRootResourceId:
'Fn::ImportValue': apigw-rootResourceId
Run Code Online (Sandbox Code Playgroud)
当我执行一个sls deploy --stage dev一切正常时,但是当我执行另一个部署到sls deploy --stage prod
出现此错误。
Another resource …Run Code Online (Sandbox Code Playgroud) 我们计划基于play框架开发一些微服务。他们将提供 REST API,其中很多将在后台使用 akka 集群/集群分片。
我们希望有一个 api 网关来公开我们内部服务的 api,但我们面临一个大问题:
- 每个服务的多个实例将在某个 ip 和端口下运行。
- API 网关如何知道服务实例在哪里运行?
- 是否有类似负载平衡器的东西可以跟踪所有正在运行的服务?
哪种解决方案可以填补“API 网关”/“负载均衡器”的空缺?
假设我有 2 个这样的端点
在情况 1 中,我将上面的数组传递给RouteClaimsRequirement,如下所示
"RouteClaimsRequirement": {
"order_perm": ["order_create", "order_edit"]
}
Run Code Online (Sandbox Code Playgroud)
但当应用程序启动时它会崩溃,并且在情况 2 中。我这样设置
"RouteClaimsRequirement": {
"order_perm": ""
}
Run Code Online (Sandbox Code Playgroud)
但用户声称“order_perm”:“create_order”授权失败。
RouteClaimsRequirement是否支持这些用例?如果是这样我该怎么做?
我正在开发一个 Spring Boot 应用程序。其中有API-Gateway和三个微服务。当我从 UI 调用 API 时,它会抛出 CORS 错误。
错误:
访问控制允许来源标头包含多个值,但只允许一个
我已经在 API-Gateway 的 application.yml 中配置了 cors。
spring:
application:
name: api-gateway
cache:
type: redis
redis:
host: 'http://localhost'
port: 6379
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
eureka:
client:
eureka-server-d-n-s-name: my.dns
eureka-service-url-Context: eureka
fetch-registry: false
region: ap-south-1b
register-with-eureka: false
use-dns-for-fetching-service-urls: true
datacenter: cloud
ribbon:
eureka:
enabled: false
server:
port: 8765
zuul:
routes:
order-service:
url: 'http://localhost:8088'
product-service:
url: 'http://localhost:8084'
user-service:
url: 'http://localhost:8082'
Run Code Online (Sandbox Code Playgroud)
除此之外,我还在每个微服务中配置了 CORS。如果我直接调用微服务,而不是通过 API-Gateway 调用 API,它工作得很好。
我在 Spring Boot 微服务中为其他微服务提供了一个 api,并且我想在这个微服务前面放置一个 spring-cloud-gateway。
我已经查看了著名的 spring 文档(https://spring.io/guides/gs/gateway/),但据我了解,它要求我在单独的项目中启动云网关。但我想在我的微服务中运行 RouteLocator bean。不是在单独的项目中,而是在同一个项目中。
当我在同一个项目中使用它时,我收到这样的警告
“在类路径中发现 Spring MVC,目前与 Spring Cloud Gateway 不兼容。请删除 spring-boot-starter-web 依赖项。”
后来,正如他在警告中所说,我删除了 spring-boot-starter-web 依赖项,甚至进入了其他项目,将它们从那里排除,如下所示
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这次我逻辑上得到了错误
“org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类 [com.company Operations.Service OperationsApplication] 的导入候选者;嵌套异常为 org.spring..core.NestedIOException:无法加载类 [javax.servlet. Filter];嵌套异常是java.lang.ClassNotFoundException: javax.servlet.Filter”。
我们从应该提供Web api服务的项目中删除了核心库:D
如果不可能在同一个项目中使用它,那么众所周知的网关实践应该如何,我应该在每个 api 微服务前面放置一个网关,还是应该在我的项目中拥有一个由多个 api 微服务组成的网关一个微服务?
spring spring-boot microservices api-gateway spring-cloud-gateway
我正在配置 spring cloud api gateway 以支持多个安全链。为此,我使用了几个安全过滤器链,它们在特定安全标头存在时触发:
如果我调整当前设置以在授权标头存在时触发第二个 (idp) 链(并使用 IDP 令牌进行调用),则一切正常。通过这种方式,安全链根据 idp jwk 验证授权标头中期望的令牌。但此标头已保留用于旧版身份验证。
我想我需要一种方法来指向 spring 资源服务器链寻找新的标头名称。
我的安全依赖项:
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
Run Code Online (Sandbox Code Playgroud)
我的配置
@EnableWebFluxSecurity
public class WebSecurityConfiguration {
// ...
@Bean
@Order(1)
public SecurityWebFilterChain iamAuthFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatcher matcher = exchange -> {
HttpHeaders headers = exchange.getRequest().getHeaders();
List<String> strings = headers.get(SurpriseHeaders.IDP_AUTH_TOKEN_HEADER_NAME);
return strings != null && strings.size() > 0
? MatchResult.match() : MatchResult.notMatch();
};
http
.securityMatcher(matcher)
.csrf().disable()
.authorizeExchange()
.pathMatchers(navigationService.getAuthFreeEndpoints()).permitAll()
.anyExchange().authenticated()
.and()
.oauth2ResourceServer(OAuth2ResourceServerSpec::jwt)
.oauth2ResourceServer().jwt().jwkSetUri(getJwkUri())
.and()
.and()
.addFilterAt(new …Run Code Online (Sandbox Code Playgroud) spring-security spring-security-oauth2 spring-oauth2 api-gateway
我试图建立一个非常简单的表格,就像在这个例子中一样,但它不起作用。当我在 API Gateway 的 AWS 控制台中对其进行测试时,总是得到以下响应:
转换前的端点响应正文:{"__type":"com.amazon.coral.service#UnknownOperationException"}
我的映射表如下所示:
#set($inputRoot = $input.path('$'))
{
"TableName": "Subscriptions",
"Item": {
"subscriptionId": {
"S": "$inputRoot.subscriptionId"
},
"userId": {
"S": "$inputRoot.userId"
},
"durationInMonth": {
"S": "$inputRoot.durationInMonth"
},
"sku": {
"S": "$inputRoot.sku"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的 Requestbody 看起来像这样。
{
"userId": "4",
"subscriptionId": "5",
"sku": "12345",
"durationInMonth": "1"
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢你的帮助。周末愉快。
娜塔莉
amazon-web-services amazon-dynamodb aws-api-gateway amazon-dynamodb-streams api-gateway
@here,请帮助我理解使用 API Gateway 的微服务身份验证。
让我们举个例子 - 我有 10 个不同的独立部署的微服务,我已经为所有这些微服务实现了 API 网关,这意味着所有请求都将通过该网关传递,而不是在我在 API 网关中添加的每个微服务中添加授权/JWt这种方法一切正常,但我的怀疑和问题是
1 如果最终用户拥有已部署微服务的 URL 并且他尝试在没有网关的情况下连接它怎么办(因为我在这里没有授权位置,我该如何阻止,我是否需要在每个微服务中添加相同的授权逻辑作为好吧,但这最终会重复代码,那么API网关的用途是什么。
让我知道是否需要任何其他输入,希望我正确解释了我的问题。
感谢
CP 瓦里亚尼
假设您正在将微服务与 Docker 容器和 Kubernetes 结合使用。
如果您在微服务前使用 API 网关(例如 Azure API 网关)来处理复合 UI 和身份验证,您还需要一个服务网格来处理服务发现和断路器吗?Azure API Gateway 中是否有任何功能可以应对此类挑战?如何?
我按照官方安装指南安装了kong。现在开始我应该给kong.conf文件?我找不到它在哪里。
kong start [-c /path/to/kong.conf]
api-gateway ×10
asp.net-core ×2
spring-boot ×2
azure ×1
cors ×1
istio ×1
java ×1
kong ×1
kubernetes ×1
ocelot ×1
serverless ×1
spring ×1