Dan Van Brunt
09/23/2021, 2:11 PMApi
? I see the permissions but I can’t seem to figure out how that can translate to something like this…Dan Van Brunt
09/23/2021, 2:13 PMassumedBy
Dan Van Brunt
09/23/2021, 2:25 PMA PolicyStatement used in an identity-based policy cannot specify any IAM principals.is what SST is giving me now with…
const api = new sst.Api(this, 'Api', {
defaultFunctionProps: {
timeout: 20,
},
routes: {
'GET /callback': 'src/lambda.callback',
'GET /install': 'src/lambda.install',
'GET /webhook': {
function: {
handler: 'src/lambda.install',
permissions: [
new iam.PolicyStatement({
actions: ['events:PutEvents'],
effect: iam.Effect.ALLOW,
principals: [new iam.ServicePrincipal('<http://apigateway.amazonaws.com|apigateway.amazonaws.com>')],
resources: [`arn:aws:events:${region}:${account}:event-bus/default`],
}),
],
},
},
},
})
thdxr
09/23/2021, 2:49 PMthdxr
09/23/2021, 2:49 PMiam.Role
toDan Van Brunt
09/23/2021, 2:50 PMthdxr
09/23/2021, 2:51 PMDan Van Brunt
09/23/2021, 2:52 PMthdxr
09/23/2021, 2:53 PMthdxr
09/23/2021, 2:53 PMDan Van Brunt
09/23/2021, 2:53 PMconst webhookRole = new iam.Role(this, 'request-lambda-role', {
assumedBy: new iam.ServicePrincipal('<http://apigateway.amazonaws.com|apigateway.amazonaws.com>'),
inlinePolicies: {
AllowLambdaServiceToAssumeRole: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents',
'logs:DescribeLogStreams',
],
resources: ['arn:aws:logs:*:*:*'],
}),
new iam.PolicyStatement({
actions: ['events:PutEvents'],
effect: iam.Effect.ALLOW,
resources: [`arn:aws:events:${region}:${account}:event-bus/default`],
}),
],
}),
},
})
Dan Van Brunt
09/23/2021, 2:54 PMconst webhookRole = new iam.Role(this, 'request-lambda-role', {
assumedBy: new iam.ServicePrincipal('<http://apigateway.amazonaws.com|apigateway.amazonaws.com>'),
inlinePolicies: {
AllowLambdaServiceToAssumeRole: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
actions: ['events:PutEvents'],
effect: iam.Effect.ALLOW,
resources: [`arn:aws:events:${region}:${account}:event-bus/default`],
}),
],
}),
},
})
thdxr
09/23/2021, 2:54 PMDan Van Brunt
09/23/2021, 2:54 PMthdxr
09/23/2021, 2:55 PMthdxr
09/23/2021, 2:55 PMDan Van Brunt
09/23/2021, 2:56 PMthdxr
09/23/2021, 2:58 PMDan Van Brunt
09/23/2021, 2:59 PMthdxr
09/23/2021, 2:59 PMDan Van Brunt
09/23/2021, 3:00 PMthdxr
09/23/2021, 3:00 PMthdxr
09/23/2021, 3:00 PMthis.role.addManagedPolicy(
iam.ManagedPolicy.fromAwsManagedPolicyName(
"service-role/AWSLambdaBasicExecutionRole"
)
)
I added this to my rolethdxr
09/23/2021, 3:00 PMDan Van Brunt
09/23/2021, 3:00 PMthdxr
09/23/2021, 3:01 PMthdxr
09/23/2021, 3:01 PMfunction: {
permissions: [ new iam.PolicyStatement({...}) ]
}
Dan Van Brunt
09/23/2021, 3:01 PMDan Van Brunt
09/23/2021, 3:01 PMDan Van Brunt
09/23/2021, 3:01 PMDan Van Brunt
09/23/2021, 3:01 PMassumedBy: new iam.CompositePrincipal(
new iam.ServicePrincipal('<http://lambda.amazonaws.com|lambda.amazonaws.com>'),
new iam.ServicePrincipal('<http://apigateway.amazonaws.com|apigateway.amazonaws.com>'),
),
inlinePolicies: {
AllowLambdaServiceToAssumeRole: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
actions: ['events:PutEvents'],
effect: iam.Effect.ALLOW,
resources: [`arn:aws:events:${region}:${account}:event-bus/default`],
}),
],
}),
},
thdxr
09/23/2021, 3:02 PMDan Van Brunt
09/23/2021, 3:02 PMthdxr
09/23/2021, 3:02 PMDan Van Brunt
09/23/2021, 3:02 PMDan Van Brunt
09/23/2021, 3:03 PMDan Van Brunt
09/23/2021, 3:03 PM