Created
May 29, 2020 20:44
-
-
Save fieldju/981935d5a57051a09978ce717c00b5a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get } from '@nestjs/common'; | |
import HealthCheckResponse from '../domain/HealthCheckResponse'; | |
import STS from 'aws-sdk/clients/sts'; | |
import { ArcUnhealthyException } from '../error/ArchUnhealthyException'; | |
@Controller('/health') | |
export default class HealthCheckController { | |
private readonly secureTokenService: STS; | |
constructor(secureTokenService: STS) { | |
this.secureTokenService = secureTokenService; | |
} | |
@Get() | |
async getHealth(): Promise<HealthCheckResponse> { | |
try { | |
const getCallerIdentityResponse = await this.secureTokenService.getCallerIdentity().promise() | |
return { | |
status: 'healthy', | |
arn: getCallerIdentityResponse.Arn | |
} | |
} catch (e) { | |
throw new ArcUnhealthyException({ | |
status: 'unhealthy', | |
msg: e | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment