-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share a single lambda service role across all lambda functions
This reduces the chance of reaching the AWS service quota limit of 1000 IAM roles per account when deploying many stacks with multiple lambdas per stack.
- Loading branch information
1 parent
d506d76
commit 7aca3a8
Showing
6 changed files
with
69 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type {Stack} from 'aws-cdk-lib'; | ||
|
||
import {aws_iam} from 'aws-cdk-lib'; | ||
|
||
export function createLambdaServiceRole(stack: Stack): aws_iam.IRole { | ||
return new aws_iam.Role(stack, `LambdaServiceRole`, { | ||
assumedBy: new aws_iam.ServicePrincipal(`lambda.amazonaws.com`), | ||
managedPolicies: [ | ||
aws_iam.ManagedPolicy.fromAwsManagedPolicyName( | ||
`service-role/AWSLambdaBasicExecutionRole`, | ||
), | ||
aws_iam.ManagedPolicy.fromAwsManagedPolicyName(`AWSXrayWriteOnlyAccess`), | ||
], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type {StackConfig} from '../read-stack-config.js'; | ||
import type {Stack, aws_apigateway, aws_iam, aws_s3} from 'aws-cdk-lib'; | ||
|
||
import {createBucketReadRole} from './create-bucket-read-role.js'; | ||
import {createBucket} from './create-bucket.js'; | ||
import {createLambdaServiceRole} from './create-lambda-service-role.js'; | ||
import {createRequestAuthorizer} from './create-request-authorizer.js'; | ||
import {createRestApi} from './create-rest-api.js'; | ||
import {createStack} from './create-stack.js'; | ||
|
||
export interface SharedConstructs { | ||
readonly bucket: aws_s3.IBucket; | ||
readonly bucketReadRole: aws_iam.IRole; | ||
readonly lambdaServiceRole: aws_iam.IRole; | ||
readonly requestAuthorizer: aws_apigateway.IAuthorizer | undefined; | ||
readonly restApi: aws_apigateway.RestApiBase; | ||
readonly stack: Stack; | ||
} | ||
|
||
export function createSharedConstructs( | ||
stackConfig: StackConfig, | ||
): SharedConstructs { | ||
const stack = createStack(stackConfig); | ||
const bucket = createBucket(stack); | ||
|
||
return { | ||
bucket, | ||
bucketReadRole: createBucketReadRole(stack, bucket), | ||
lambdaServiceRole: createLambdaServiceRole(stack), | ||
requestAuthorizer: createRequestAuthorizer(stackConfig, stack), | ||
restApi: createRestApi(stackConfig, stack), | ||
stack, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters