作为AWS SAM模板的一部分,我有一个带有HttpPost事件触发器的函数。因为我使用的是AWS SAM转换,所以我没有明确声明要创建的API网关来路由此http帖子以触发功能。鉴于此,有什么方法可以引用生成的URL端点,例如在堆栈输出或describe-stack-resources
中,以便我可以以编程方式获取该函数的调用URL?我知道我可以通过导航到控制台中的堆栈,找到ApiGateway资源并随机单击直到页面之一显示它来获取端点。但是我想要一种可以重用我的应用程序代码的方法。
缩短的模板以供参考:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
SendJobUpdateFunction:
Type: AWS::Serverless::Function
Properties:
...
Runtime: nodejs10.x
Events:
HttpPost:
Type: Api
Properties:
Path: '/jobs'
Method: post
...
我目前正在使用sam
CLI进行部署,我认为它的语法与aws cloudformtion
非常相似。
答案 0 :(得分:2)
根据documentation和this previous question,您可以通过以下方式获得它:
// src/app/app.routes.ts
import { Routes, CanActivate } from '@angular/router';
import { ProfileComponent } from './profile/profile.component';
import {
AuthGuardService as AuthGuard
} from './auth/auth-guard.service';
export const ROUTES: Routes = [
{ path: '', component: HomeComponent },
{
path: 'profile',
component: ProfileComponent,
canActivate: [AuthGuard]
},
{ path: '**', redirectTo: '' }
];
!Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}"
是包含部署阶段的您自己的参数。