Skip to content

Commit

Permalink
add inline role policies
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbjacobson committed Oct 23, 2023
1 parent d93b2b9 commit 9c72e28
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 1 deletion.
160 changes: 160 additions & 0 deletions cdk/lib/__snapshots__/batch-email-sender.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,86 @@ exports[`The BatchEmailSender stack matches the snapshot 1`] = `
},
"Type": "AWS::ApiGateway::Method",
},
"cloudwatchlogsinlinepolicyB03D217C": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"lambda:InvokeFunction",
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:logs:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":log-group:/aws/lambda/batch-email-sender-CODE:log-stream:*",
],
],
},
},
],
"Version": "2012-10-17",
},
"PolicyName": "cloudwatchlogsinlinepolicyB03D217C",
"Roles": [
{
"Ref": "BatchEmailSenderLambdaServiceRoleADC9CE54",
},
],
},
"Type": "AWS::IAM::Policy",
},
"sqsinlinepolicyA7B14341": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"sqs:GetQueueUrl",
"sqs:SendMessage",
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:sqs:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":braze-emails-CODE",
],
],
},
},
],
"Version": "2012-10-17",
},
"PolicyName": "sqsinlinepolicyA7B14341",
"Roles": [
{
"Ref": "BatchEmailSenderLambdaServiceRoleADC9CE54",
},
],
},
"Type": "AWS::IAM::Policy",
},
},
}
`;
Expand Down Expand Up @@ -2408,6 +2488,86 @@ exports[`The BatchEmailSender stack matches the snapshot 2`] = `
},
"Type": "AWS::ApiGateway::Method",
},
"cloudwatchlogsinlinepolicyB03D217C": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"lambda:InvokeFunction",
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:logs:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":log-group:/aws/lambda/batch-email-sender-PROD:log-stream:*",
],
],
},
},
],
"Version": "2012-10-17",
},
"PolicyName": "cloudwatchlogsinlinepolicyB03D217C",
"Roles": [
{
"Ref": "BatchEmailSenderLambdaServiceRoleADC9CE54",
},
],
},
"Type": "AWS::IAM::Policy",
},
"sqsinlinepolicyA7B14341": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"sqs:GetQueueUrl",
"sqs:SendMessage",
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:sqs:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":braze-emails-PROD",
],
],
},
},
],
"Version": "2012-10-17",
},
"PolicyName": "sqsinlinepolicyA7B14341",
"Roles": [
{
"Ref": "BatchEmailSenderLambdaServiceRoleADC9CE54",
},
],
},
"Type": "AWS::IAM::Policy",
},
},
}
`;
36 changes: 35 additions & 1 deletion cdk/lib/batch-email-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {App} from "aws-cdk-lib";
import {Duration} from "aws-cdk-lib";
import {ApiKey, CfnUsagePlanKey, Cors, UsagePlan} from "aws-cdk-lib/aws-apigateway";
import {ComparisonOperator, Metric} from "aws-cdk-lib/aws-cloudwatch";
import {Effect, Policy, PolicyStatement} from "aws-cdk-lib/aws-iam";
import {Runtime} from "aws-cdk-lib/aws-lambda";
import {CfnInclude} from "aws-cdk-lib/cloudformation-include";

Expand Down Expand Up @@ -126,6 +127,39 @@ export class BatchEmailSender extends GuStack {


// ---- Apply policies ---- //
// TODO
const cloudwatchLogsInlinePolicy: Policy = new Policy(this, "cloudwatch-logs-inline-policy", {
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
actions: [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"lambda:InvokeFunction"
],
resources: [
`arn:aws:logs:${this.region}:${this.account}:log-group:/aws/lambda/batch-email-sender-${this.stage}:log-stream:*`,
]
}),
],
})

const sqsInlinePolicy: Policy = new Policy(this, "sqs-inline-policy", {
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
actions: [
"sqs:GetQueueUrl",
"sqs:SendMessage",
],
resources: [
`arn:aws:sqs:${this.region}:${this.account}:braze-emails-${this.stage}`,
]
}),
],
})

batchEmailSenderLambda.role?.attachInlinePolicy(cloudwatchLogsInlinePolicy)
batchEmailSenderLambda.role?.attachInlinePolicy(sqsInlinePolicy)
}
}

0 comments on commit 9c72e28

Please sign in to comment.