( arn: string, principal = '906037444270', statementId = 'smartthings', )
| 2 | |
| 3 | |
| 4 | export const addPermission = async ( |
| 5 | arn: string, |
| 6 | principal = '906037444270', |
| 7 | statementId = 'smartthings', |
| 8 | ): Promise<string> => { |
| 9 | const segments = arn.split(':') |
| 10 | if (segments.length < 7) { |
| 11 | return 'Invalid Lambda ARN' |
| 12 | } |
| 13 | |
| 14 | try { |
| 15 | const region = segments[3] |
| 16 | const client = new LambdaClient({ region }) |
| 17 | |
| 18 | const params: AddPermissionRequest = { |
| 19 | Action: 'lambda:InvokeFunction', |
| 20 | FunctionName: arn, |
| 21 | Principal: principal, |
| 22 | StatementId: statementId, |
| 23 | } |
| 24 | |
| 25 | const command = new AddPermissionCommand(params) |
| 26 | |
| 27 | await client.send(command) |
| 28 | |
| 29 | return 'Authorization added' |
| 30 | } catch (error) { |
| 31 | if (error.name === 'ResourceConflictException') { |
| 32 | return 'Already authorized' |
| 33 | } |
| 34 | throw error |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export const schemaAWSPrincipal = '148790070172' |
| 39 | export const addSchemaPermission = ( |
no outgoing calls
no test coverage detected