Jack Tan
02/28/2022, 10:52 PM/aws/lambda/dev-papermind-signature-s-SignatureApisLambdaGETsi-28GoENFjgrhK
, whereas I like it to be /aws/lambda/dev-papermind-signature-service-{nameOfApi}
I have "name": "papermind-signature-service"
in sst.json
, but I guess the name is too long... hence the cut off at papermind-signature-s
SignatureApis
is from new Api(this, "SignatureApis"
, how do I get rid of this LambdaGETsi-28Go....
Garret Harp
02/28/2022, 11:12 PMJack Tan
02/28/2022, 11:17 PMhandler
.
This is what I do
export default abstract class ApiStack extends Stack {
abstract name(): string;
abstract privateRoutes(): { [key: string]: string };
abstract publicRoutes(): { [key: string]: string };
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
const api = new Api(this, this.name(), {
defaultAuthorizer: new HttpJwtAuthorizer({
jwtAudience: [env.jwtAudience],
jwtIssuer: env.jwtIssuer,
}),
defaultAuthorizationType: ApiAuthorizationType.JWT,
cors: true,
routes: {
...this.privateRoutes(),
...Object.entries(this.publicRoutes()).reduce(
(acc, [route, func]) => ({
...acc,
[route]: {
function: func,
authorizationType: ApiAuthorizationType.NONE,
},
}),
{},
),
},
});
this.addOutputs({
[`${this.name()}Endpoint`]: api.url,
});
}
}
export default class SignatureServiceStack extends ApiStack {
name() {
return 'SignatureApis';
}
privateRoutes() {
return {
'GET /signature/{teamId}/{articleId}':
'src/getSignaturesInfoHandler.handler',
};
}
publicRoutes() {
return {
'POST /signature': 'src/upsertSignatureInfoHandler.handler',
'GET /signature/verify/{teamId}/{articleId}/{versionId}/{email}':
'src/verifyIfSignatureSignedHandler.handler',
};
}
}
Garret Harp
02/28/2022, 11:18 PMGarret Harp
02/28/2022, 11:19 PM'POST /my/route': {
function: {
functionName: 'my-function-name',
handler: 'src/my/path'
}
}
Jack Tan
02/28/2022, 11:22 PMJack Tan
02/28/2022, 11:23 PMfunctionName
is not mentioned in that docs 😞Jack Tan
02/28/2022, 11:25 PMexport interface FunctionProps extends Omit<lambda.FunctionOptions, "timeout" | "runtime"> {
/**
* Path to the entry point and handler function. Of the format:
* `/path/to/file.function`.
*/
handler?: string;
/**
* The source directory where the entry point is located. The node_modules in this
* directory is used to generate the bundle.
*
* @default - Defaults to the app directory.
*/
srcPath?: string;
/**
* The runtime environment.
*
* @default - Defaults to NODEJS_12_X
*/
runtime?: "nodejs" | "nodejs4.3" | "nodejs6.10" | "nodejs8.10" | "nodejs10.x" | "nodejs12.x" | "nodejs14.x" | "python2.7" | "python3.6" | "python3.7" | "python3.8" | "dotnetcore1.0" | "dotnetcore2.0" | "dotnetcore2.1" | "dotnetcore3.1" | "go1.x" | lambda.Runtime;
/**
* The amount of memory in MB allocated.
*
* @default - Defaults to 1024
*/
memorySize?: number;
/**
* The execution timeout in seconds.
*
* @default - number
*/
timeout?: number | cdk.Duration;
/**
* Enable AWS X-Ray Tracing.
*
* @default - Defaults to ACTIVE
*/
/**
* Enable local development
*
* @default - Defaults to true
*/
enableLiveDev?: boolean;
tracing?: lambda.Tracing;
/**
* Disable bundling with esbuild.
*
* @default - Defaults to true
*/
bundle?: FunctionBundleProp;
permissions?: Permissions;
layers?: lambda.ILayerVersion[];
}
Jack Tan
02/28/2022, 11:32 PMnew Function(this, 'upsert-signature', {
handler: 'src/upsertSignatureInfoHandler.handler',
}),
Jack Tan
02/28/2022, 11:39 PM/aws/lambda/dev-papermind-signature-s-getsignatureinfoEC61D5C1-yyXeh6
I don't know what is that EC61D5...
Frank
sst.Function
inherits all props from CDK’s lambda.Function
, try this:
new Function(this, 'upsert-signature', {
handler: 'src/upsertSignatureInfoHandler.handler',
functionName: app.logicalPrefixedName("upsert-signature-info"),
}),
Frank
app
is the first element passed to the Stack’s constructor. logicalPrefixedName
prefixes the function name with the stage name and the app name.Jack Tan
03/01/2022, 12:53 AM