-
Notifications
You must be signed in to change notification settings - Fork 0
/
device-api-stack.ts
32 lines (28 loc) · 1.41 KB
/
device-api-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Stack } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import { Construct } from 'constructs';
import { SSM_PREFIX, StackCommonProps } from '../config';
/**
* /device/v1/{deviceid}
* /device/v2/{deviceid}
*/
export class DeviceApiStack extends Stack {
constructor(scope: Construct, id: string, props: StackCommonProps) {
super(scope, id, props);
const restApiId = ssm.StringParameter.valueForStringParameter(this, `${SSM_PREFIX}/rest-api-id`);
const rootResourceId = ssm.StringParameter.valueForStringParameter(this, `${SSM_PREFIX}/root-resource-id`);
const rootApi = apigateway.RestApi.fromRestApiAttributes(this, "root-api", { restApiId, rootResourceId });
const pingApiFunction = new lambda.DockerImageFunction(this, 'lambda-ping', {
functionName: 'device-api',
code: lambda.DockerImageCode.fromImageAsset('../app', {
cmd: ["hello.handler"],
entrypoint: ["/lambda-entrypoint.sh"],
})
});
const servicea = rootApi.root.addResource('device');
servicea.addResource('v1').addResource('{deviceid}').addMethod('GET', new apigateway.LambdaIntegration(pingApiFunction, { proxy: true }));
servicea.addResource('v2').addResource('{deviceid}').addMethod('GET', new apigateway.LambdaIntegration(pingApiFunction, { proxy: true }));
}
}