aws-sdk#ApiGatewayV2 TypeScript Examples
The following examples show how to use
aws-sdk#ApiGatewayV2.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getApiMapping(client: ApiGatewayV2, domainName: string, apiId: string, stageName: string, print = false) {
const { Items } = await client.getApiMappings({ DomainName: domainName }).promise();
const result = (Items || []).find(item => item.ApiId === apiId && stageName === item.Stage);
if(result) {
if (print) {
console.log(chalk`{bold.cyan - ApiMapping: }`);
console.log(` - ApiMappingId: ${result.ApiMappingId}`);
console.log(` - ApiMappingKey: ${result.ApiMappingKey}`);
console.log(` - Stage: ${result.Stage}`);
console.log(` - ApiUrl: https://${domainName}/${result.ApiMappingKey?.split('*')[0]}`);
}
return result;
}
}
Example #2
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getCustomDomain(client: ApiGatewayV2, customDomainName: string, print = false) {
try {
const result = await client.getDomainName({ DomainName: customDomainName }).promise();
if (print) {
console.log(chalk`{bold.cyan - CustomDomaim: }`);
console.log(` - DomainName: ${result.DomainName}`);
}
return result;
} catch (error) {
if (error.statusCode !== 404) {
throw error;
}
}
}
Example #3
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function createClients(region: string, credentials: Credentials) {
const clientConfig = {
region,
credentials: {
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.accessKeySecret,
sessionToken: credentials.token
}
};
return {
lambdaClient: new Lambda(clientConfig),
apiGatewayClient: new ApiGatewayV2(clientConfig),
iamClient: new IAM(clientConfig)
}
}
Example #4
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getIntegration(client: ApiGatewayV2, apiId: string, print = false) {
const { Items } = await client.getIntegrations({ ApiId: apiId, MaxResults: '500' }).promise();
const items = Items || []
if (items.length > 1) {
throw new Error(`There are two or more integrations in the api [${apiId}]`);
} else if (items.length === 1) {
const result = items[0];
if (print) {
console.log(chalk`{bold.cyan - Integration: }`);
console.log(` - IntegrationId: ${result.IntegrationId}`);
console.log(` - PayloadFormatVersion: ${result.PayloadFormatVersion}`);
console.log(` - TimeoutInMillis: ${result.TimeoutInMillis}`);
}
return result;
}
}
Example #5
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getApi(client: ApiGatewayV2, apiName: string, print = false, stageName?: string) {
const { Items } = await client.getApis({ MaxResults: '500' }).promise();
const items = (Items || []).filter(item => item.Name === apiName);
if (items.length > 1) {
throw new Error(`There are two or more apis named [${apiName}] in the api gateway`);
} else if (items.length === 1) {
const result = items[0];
if (print) {
console.log(chalk`{bold.cyan - API: }`);
console.log(` - ApiId: ${result.ApiId}`);
console.log(` - ApiName: ${result.Name}`);
console.log(` - ApiEndpoint: ${result.ApiEndpoint}`);
console.log(` - ProtocolType: ${result.ProtocolType}`);
console.log(` - ApiUrl: ${result.ApiEndpoint}/${stageName}/`);
}
return result;
}
}
Example #6
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getRoute(client: ApiGatewayV2, apiId: string, print = false) {
const { Items } = await client.getRoutes({ ApiId: apiId }).promise();
const items = Items || [];
if (items.length > 1) {
throw new Error(`There are two or more routes in the api [${apiId}]`);
} else if (items.length === 1) {
const result = items[0];
if (print) {
console.log(chalk`{bold.cyan - Route: }`);
console.log(` - RouteId: ${result.RouteId}`);
console.log(` - RouteKey: ${result.RouteKey}`);
}
return result;
}
}
Example #7
Source File: utils.ts From malagu with MIT License | 7 votes |
export async function getStage(client: ApiGatewayV2, apiId: string, stageName: string, print = false) {
try {
const result = await client.getStage({ ApiId: apiId, StageName: stageName }).promise();
if (print) {
console.log(chalk`{bold.cyan - Stage: }`);
console.log(` - StageName: ${result.StageName}`);
console.log(` - LastUpdatedDate: ${result.LastUpdatedDate}`);
}
return result;
} catch (error) {
if (error.statusCode !== 404) {
throw error;
}
}
}
Example #8
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseUpdateApiRequest(apiMeta: any, apiId: string) {
const createApiRequest: any = parseCreateApiRequest(apiMeta);
delete createApiRequest.ProtocolType;
delete createApiRequest.Tags;
const req: ApiGatewayV2.UpdateApiRequest = {
...createApiRequest,
ApiId: apiId
};
return req;
}
Example #9
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseUpdateStageRequest(stageMeta: any, apiId: string, deploymentId?: string) {
const req: ApiGatewayV2.UpdateStageRequest = {
StageName: stageMeta.name,
ApiId: apiId,
ClientCertificateId: stageMeta.clientCertificateId,
AutoDeploy: stageMeta.autoDeploy,
DeploymentId: deploymentId,
RouteSettings: stageMeta.routeSettings,
Description: stageMeta.description,
StageVariables: stageMeta.stageVariables
};
const { defaultRouteSettings, accessLogSettings } = stageMeta;
if (defaultRouteSettings) {
req.DefaultRouteSettings = {
DataTraceEnabled: defaultRouteSettings.dataTraceEnabled,
DetailedMetricsEnabled: defaultRouteSettings.detailedMetricsEnabled,
LoggingLevel: defaultRouteSettings.loggingLevel,
ThrottlingBurstLimit: defaultRouteSettings.throttlingBurstLimit,
ThrottlingRateLimit: defaultRouteSettings.throttlingRateLimit,
};
}
if (accessLogSettings) {
req.AccessLogSettings = {
DestinationArn: accessLogSettings.destinationArn,
Format: accessLogSettings.format
};
}
return req;
}
Example #10
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseCreateApiMappingRequest(apiMappingMeta: any, domainName: string, apiId: string, stageName: string) {
const req: ApiGatewayV2.CreateApiMappingRequest = {
ApiId: apiId,
Stage: stageName,
DomainName: domainName,
ApiMappingKey: apiMappingMeta.apiMappingKey
};
return req;
}
Example #11
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseUpdateDomainNameRequest(customDomainMeta: any, apiEndpoint: string) {
const req: ApiGatewayV2.UpdateDomainNameRequest = {
DomainName: customDomainMeta.name
};
const { domainNameConfigurations, mutualTlsAuthentication } = customDomainMeta;
if (domainNameConfigurations) {
req.DomainNameConfigurations = [];
for (const config of domainNameConfigurations) {
req.DomainNameConfigurations.push({
ApiGatewayDomainName: config.ApiGatewayDomainName || apiEndpoint.replace('https://', ''),
CertificateArn: config.certificateArn,
CertificateName: config.certificateName,
DomainNameStatus: config.domainNameStatus,
CertificateUploadDate: config.certificateUploadDate,
DomainNameStatusMessage: config.domainNameStatusMessage,
EndpointType: config.endpointType,
HostedZoneId: config.hostedZoneId,
SecurityPolicy: config.SecurityPolicy
});
}
}
if (mutualTlsAuthentication) {
req.MutualTlsAuthentication = {
TruststoreUri: mutualTlsAuthentication.truststoreUri,
TruststoreVersion: mutualTlsAuthentication.truststoreVersion
};
}
return req;
}
Example #12
Source File: deploy.ts From malagu with MIT License | 6 votes |
async function createOrUpdateRoute(routeMeta: any, apiId: string, integrationId: string) {
const routeInfo = await getRoute(apiGatewayClient, apiId);
let result: ApiGatewayV2.UpdateRouteResult | ApiGatewayV2.CreateRouteResult;
if (routeInfo) {
const routeId = routeInfo.RouteId!;
await SpinnerUtil.start(`Update route: ${routeMeta.routeKey}`, async () => {
result = await apiGatewayClient.updateRoute(parseUpdateRouteRequest(routeMeta, apiId, integrationId, routeId)).promise();
});
} else {
await SpinnerUtil.start(`Create route: ${routeMeta.routeKey}`, async () => {
result = await apiGatewayClient.createRoute(parseCreateRouteRequest(routeMeta, apiId, integrationId)).promise();
});
}
return result!;
}
Example #13
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseUpdateRouteRequest(routeMeta: any, apiId: string, integrationId: string, routeId: string) {
const req: ApiGatewayV2.UpdateRouteRequest = {
...parseCreateRouteRequest(routeMeta, apiId, integrationId),
ApiId: apiId,
RouteId: routeId
};
return req;
}
Example #14
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseCreateRouteRequest(routeMeta: any, apiId: string, integrationId: string) {
const req: ApiGatewayV2.CreateRouteRequest = {
ApiId: apiId,
ApiKeyRequired: routeMeta.apiKeyRequired,
AuthorizationScopes: routeMeta.authorizationScopes,
AuthorizationType: routeMeta.authorizationType,
AuthorizerId: routeMeta.authorizerId,
ModelSelectionExpression: routeMeta.modelSelectionExpression,
OperationName: routeMeta.operationName,
RequestModels: routeMeta.requestModels,
RequestParameters: routeMeta.requestParameters,
RouteKey: routeMeta.routeKey,
RouteResponseSelectionExpression: routeMeta.routeResponseSelectionExpression,
Target: `integrations/${integrationId}`
};
return req;
}
Example #15
Source File: deploy.ts From malagu with MIT License | 6 votes |
async function createOrUpdateIntegration(integrationMeta: any, apiId: string) {
const integrationInfo = await getIntegration(apiGatewayClient, apiId);
let result: ApiGatewayV2.UpdateIntegrationResult | ApiGatewayV2.CreateIntegrationResult;
if (integrationInfo) {
const integrationId = integrationInfo.IntegrationId!;
await SpinnerUtil.start(`Update ${integrationId} integration`, async () => {
result = await apiGatewayClient.updateIntegration(parseUpdateIntegrationRequest(integrationMeta, apiId, integrationId)).promise();
});
} else {
await SpinnerUtil.start('Create integration', async () => {
result = await apiGatewayClient.createIntegration(parseCreateIntegrationRequest(integrationMeta, apiId)).promise();
});
}
return result!;
}
Example #16
Source File: deploy.ts From malagu with MIT License | 6 votes |
async function createOrUpdateApi(api: any, functionName: string, aliasName: string, region: string, accountId: string) {
const apiName = api.name;
const apiInfo = await getApi(apiGatewayClient, apiName);
let result: ApiGatewayV2.UpdateApiResponse | ApiGatewayV2.CreateApiResponse;
if (apiInfo) {
result = await SpinnerUtil.start(`Update ${apiName} api`, async () => {
const apiId = apiInfo.ApiId!;
return apiGatewayClient.updateApi(parseUpdateApiRequest(api, apiId)).promise();
});
} else {
result = await SpinnerUtil.start(`Create ${apiName} api`, () => apiGatewayClient.createApi(parseCreateApiRequest(api)).promise());
await lambdaClient.addPermission({
FunctionName: `arn:aws:lambda:${region}:${accountId}:function:${functionName}:${aliasName}`,
StatementId: v4(),
Action: 'lambda:InvokeFunction',
Principal: 'apigateway.amazonaws.com',
SourceArn: `arn:aws:execute-api:${region}:${accountId}:${result.ApiId}/*/*/*`
}).promise();
}
return result;
}
Example #17
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseUpdateIntegrationRequest(integrationMeta: any, apiId: string, integrationId: string) {
const req: ApiGatewayV2.UpdateIntegrationRequest = {
...parseCreateIntegrationRequest(integrationMeta, apiId),
ApiId: apiId,
IntegrationId: integrationId,
};
return req;
}
Example #18
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseCreateIntegrationRequest(integrationMeta: any, apiId: string) {
const req: ApiGatewayV2.CreateIntegrationRequest = {
ApiId: apiId,
IntegrationType: integrationMeta.integrationType,
ConnectionId: integrationMeta.connectionId,
ConnectionType: integrationMeta.connectionType,
ContentHandlingStrategy: integrationMeta.contentHandlingStrategy,
CredentialsArn: integrationMeta.credentialsArn,
Description: integrationMeta.description,
IntegrationMethod: integrationMeta.integrationMethod,
IntegrationSubtype: integrationMeta.integrationSubtype,
IntegrationUri: integrationMeta.integrationUri,
PassthroughBehavior: integrationMeta.passthroughBehavior,
PayloadFormatVersion: integrationMeta.payloadFormatVersion,
RequestParameters: integrationMeta.requestParameters,
RequestTemplates: integrationMeta.requestTemplates,
TemplateSelectionExpression: integrationMeta.templateSelectionExpression,
TimeoutInMillis: integrationMeta.timeoutInMillis
};
const { tlsConfig } = integrationMeta;
if (tlsConfig) {
req.TlsConfig = {
ServerNameToVerify: tlsConfig.serverNameToVerify
};
}
return req;
}
Example #19
Source File: deploy.ts From malagu with MIT License | 6 votes |
function parseCreateApiRequest(apiMeta: any) {
const req: ApiGatewayV2.CreateApiRequest = {
Name: apiMeta.name,
ProtocolType: apiMeta.protocolType,
Description: apiMeta.description,
ApiKeySelectionExpression: apiMeta.apiKeySelectionExpression,
CredentialsArn: apiMeta.credentialsArn,
DisableExecuteApiEndpoint: apiMeta.disableExecuteApiEndpoint,
DisableSchemaValidation: apiMeta.disableSchemaValidation,
RouteKey: apiMeta.routeKey,
RouteSelectionExpression: apiMeta.routeSelectionExpression,
Tags: apiMeta.tags,
Target: apiMeta.target,
Version: apiMeta.version
};
const { corsConfiguration } = apiMeta;
if (corsConfiguration) {
req.CorsConfiguration = {
AllowCredentials: corsConfiguration.allowCredentials,
AllowHeaders: corsConfiguration.allowHeaders,
AllowMethods: corsConfiguration.allowMethods,
AllowOrigins: corsConfiguration.allowOrigins,
ExposeHeaders: corsConfiguration.exposeHeaders,
MaxAge: corsConfiguration.maxAge
};
}
return req;
}
Example #20
Source File: deploy.ts From malagu with MIT License | 5 votes |
function parseCreateDomainNameRequest(customDomainMeta: any, apiEndpoint: string) {
const req: ApiGatewayV2.CreateDomainNameRequest = {
...parseUpdateDomainNameRequest(customDomainMeta, apiEndpoint),
};
return req;
}
Example #21
Source File: deploy.ts From malagu with MIT License | 5 votes |
function parseUpdateApiMappingRequest(apiMappingMeta: any, domainName: string, apiId: string, stageName: string, apiMappingId: string) {
const req: ApiGatewayV2.UpdateApiMappingRequest = {
...parseCreateApiMappingRequest(apiMappingMeta, domainName, apiId, stageName),
ApiMappingId: apiMappingId,
};
return req;
}
Example #22
Source File: deploy.ts From malagu with MIT License | 5 votes |
function parseCreateStageRequest(stageMeta: any, apiId: string, deploymentId?: string) {
const req: ApiGatewayV2.CreateStageRequest = {
...parseUpdateStageRequest(stageMeta, apiId, deploymentId)
};
return req;
}
Example #23
Source File: deploy.ts From malagu with MIT License | 5 votes |
apiGatewayClient: ApiGatewayV2
Example #24
Source File: info.ts From malagu with MIT License | 5 votes |
apiGatewayClient: ApiGatewayV2