Hey all, anyone knows how to rename the Cloudwatch...
# help
j
Hey all, anyone knows how to rename the Cloudwatch logs? My log is called
/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....
g
you have to manually name the lambda function as the log group uses the lambdas name
j
My lambda function name is called
handler
. This is what I do
Copy code
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,
    });
  }
}
Copy code
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',
    };
  }
}
g
I mean the actual function name in aws not anything with the code of it. You have to use the full config to set the function name: https://docs.serverless-stack.com/constructs/Api#using-the-full-config
ie
Copy code
'POST /my/route': {
  function: {
    functionName: 'my-function-name',
    handler: 'src/my/path'
  }
}
j
Ohhh okay, thanks Ill give it a go
functionName
is not mentioned in that docs 😞
Hmm, functionName does not exist.
Copy code
export 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[];
}
Im going to try and see if this works
Copy code
new Function(this, 'upsert-signature', {
        handler: 'src/upsertSignatureInfoHandler.handler',
      }),
So close!
/aws/lambda/dev-papermind-signature-s-getsignatureinfoEC61D5C1-yyXeh6
I don't know what is that
EC61D5...
f
Hi @Jack Tan,
sst.Function
inherits all props from CDK’s
lambda.Function
, try this:
Copy code
new Function(this, 'upsert-signature', {
  handler: 'src/upsertSignatureInfoHandler.handler',
  functionName: app.logicalPrefixedName("upsert-signature-info"),
}),
app
is the first element passed to the Stack’s constructor.
logicalPrefixedName
prefixes the function name with the stage name and the app name.
j
@Frank Thanks so much! It works!