diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index b9a3d7e..40c5c61 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -69,6 +69,7 @@ jobs: - name: Install project dependencies run: cd infra && yarn install - name: Bootstrap CDK + if: ${{ vars.CDK_BOOTSTRAP == 'true' }} working-directory: infra run: | yarn cdk bootstrap diff --git a/infra/stacks/iam-stack.ts b/infra/stacks/iam-stack.ts index c263582..4f98174 100644 --- a/infra/stacks/iam-stack.ts +++ b/infra/stacks/iam-stack.ts @@ -10,6 +10,7 @@ import { AWS_ACCOUNT_ID, AWS_REGION, BaseStackProps, + getLambdaExecRoleName, getResourceId, } from '../utils'; @@ -24,7 +25,7 @@ export class IAMStack extends Stack { getResourceId('LambdaFunctionExecutionRole', name), { assumedBy: new ServicePrincipal('lambda.amazonaws.com'), - roleName: `${this.stackName}-${name}-lambda-function-execution`, + roleName: getLambdaExecRoleName(name), managedPolicies: [ ManagedPolicy.fromAwsManagedPolicyName( 'service-role/AWSLambdaBasicExecutionRole' diff --git a/infra/stacks/lambda-stack.ts b/infra/stacks/lambda-stack.ts index 704add3..1face04 100644 --- a/infra/stacks/lambda-stack.ts +++ b/infra/stacks/lambda-stack.ts @@ -10,6 +10,7 @@ import { AWS_ACCOUNT_ID, AWS_REGION, BaseStackProps, + getLambdaExecRoleName, getResourceId, } from '../utils'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; @@ -22,7 +23,6 @@ export class LambdaStack extends Stack { new Function(this, getResourceId('LambdaFunction', name), { runtime: Runtime.NODEJS_20_X, code: Code.fromAsset(`../dist/apps/${name}`), - timeout: Duration.seconds(50), // ? https://stackoverflow.com/questions/36419442/the-role-defined-for-the-function-cannot-be-assumed-by-lambda environment: {}, handler: 'main.handler', role: Role.fromRoleName( @@ -30,7 +30,7 @@ export class LambdaStack extends Stack { getResourceId('IAM', name), `${this.stackName}-${name}-lambda-function-execution` ), - functionName: `${this.stackName}-${name}`, + functionName: getLambdaExecRoleName(name), }); }); } diff --git a/infra/utils.ts b/infra/utils.ts index 5105cd2..7cacdb4 100644 --- a/infra/utils.ts +++ b/infra/utils.ts @@ -23,3 +23,7 @@ const camalize = (str: string) => { export const getResourceId = (resourceName: string, funcName: string) => { return `${camalize(funcName)}${resourceName}`; }; + +export const getLambdaExecRoleName = (funcName: string) => { + return `${ENVIRONMENT}-${funcName}-lambda-function-execution`; +};