Adrián Mouly
08/30/2021, 6:10 AMFunction
?Frank
Function as Fn
works:
import { Function as Fn } from "@serverless-stack/resources";
Jad
08/30/2021, 1:26 PM/*
Interfaces
*/
interface SharedStackProps extends sst.StackProps {
readonly sharedFunction: sst.Function,
}
/*
📁Index.ts
*/
import StackCommonResources from '@stacks/StackCommonResources'
import StackOne from '@stacks/StackOne'
// Stack in which shared functions are created
const stackCommonResources = new StackCommonResources(app, 'StackCommonResources')
const sharedStackProps = {
sharedFunction: stackCommonResources.sharedFunction
}
// Stack consuming shared functions
const stackOne = new StackOne(app, 'StackOne', sharedStackProps)
/*
📁stackCommonResources.ts
This stack defines a shared function
*/
export default class StackCommonResources extends sst.Stack {
public readonly sharedFunction: sst.Function
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props)
this.sharedFunction = new sst.Function(this, 'sharedFunction', {
handler: 'src/sharedFunction/index.handler',
functionName: `${scope.stage}-my-shared-function`,
...
})
this.addOutputs({})
}
}
/*
📁stackOne.ts
This stack imports a function from stackCommonResources
*/
export default class StackOne extends sst.Stack {
public readonly sharedFunction: sst.Function
constructor(scope: <http://sst.App|sst.App>, id: string, props: SharedStackProps) {
super(scope, id, props)
const authorizer = new apigateway.TokenAuthorizer(this, 'authorizer', {
handler: props.sharedFunction,
...
})
this.addOutputs({})
}
}
Adrián Mouly
08/30/2021, 3:37 PMFunction as Fn
worked.Adrián Mouly
08/30/2021, 3:38 PMsst
way.Adrián Mouly
08/30/2021, 3:38 PMimport { Api, App, Queue, Stack, StackProps, Topic, Function as SstFunction } from ‘@serverless-stack/resources’;