Skip to content

Commit 1d600d1

Browse files
committed
CHANGE: lambda name
1 parent 17fe834 commit 1d600d1

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

src/cli/context/steppes/setFunctionalEnvironment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ export class SetFunctionalEnvironmentStep extends ExecuteStep {
55
for (let serviceDefinition of context.publishedFunctions) {
66
const setFuncEnvEnvAttrib = environment('FUNCTIONAL_ENVIRONMENT', context.FUNCTIONAL_ENVIRONMENT)
77
const setStageEnvAttrib = environment('FUNCTIONAL_STAGE', context.stage)
8+
const setProjectNameEnvAttrib = environment('FUNCTIONAL_PROJECTNAME', context.projectName)
89
setFuncEnvEnvAttrib(serviceDefinition.service)
910
setStageEnvAttrib(serviceDefinition.service)
11+
setProjectNameEnvAttrib(serviceDefinition.service)
1012
}
1113
}
1214
}

src/cli/project/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ try {
1313
if (packageJson && packageJson.version) {
1414
projectConfig.version = packageJson.version
1515
}
16-
if (packageJson && packageJson.name) {
16+
if (!projectConfig.name && packageJson && packageJson.name) {
1717
projectConfig.name = packageJson.name
1818
}
1919
} catch (e) { }

src/cli/providers/cloudFormation/context/resources.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const logPolicy = async (context) => {
179179
],
180180
"Resource": [
181181
{
182-
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*-" + context.stage + ":*"
182+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/" + context.projectName + "-*-" + context.stage + ":*"
183183
}
184184
]
185185
}, {
@@ -189,7 +189,7 @@ export const logPolicy = async (context) => {
189189
],
190190
"Resource": [
191191
{
192-
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*-" + context.stage + ":*:*"
192+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/" + context.projectName + "-*-" + context.stage + ":*:*"
193193
}
194194
]
195195
}]
@@ -276,7 +276,7 @@ export const lambdaResource = async (context) => {
276276
S3Key: context.S3Zip
277277
},
278278
Description: serviceDefinition[CLASS_DESCRIPTIONKEY] || getMetadata(CLASS_DESCRIPTIONKEY, serviceDefinition.service),
279-
FunctionName: `${getFunctionName(serviceDefinition.service)}-${context.stage}`,
279+
FunctionName: `${context.projectName}-${getFunctionName(serviceDefinition.service)}-${context.stage}`,
280280
Handler: serviceDefinition.handler,
281281
MemorySize: serviceDefinition[CLASS_AWSMEMORYSIZEKEY] || getMetadata(CLASS_AWSMEMORYSIZEKEY, serviceDefinition.service),
282282
Role: serviceDefinition[CLASS_ROLEKEY] || getMetadata(CLASS_ROLEKEY, serviceDefinition.service),
@@ -335,7 +335,7 @@ export const lambdaLogResource = async (context) => {
335335
const functionName = getFunctionName(serviceDefinition.service)
336336

337337
const properties: any = {
338-
"LogGroupName": `/aws/lambda/${functionName}-${context.stage}`
338+
"LogGroupName": `/aws/lambda/${context.projectName}-${functionName}-${context.stage}`
339339
};
340340

341341
const lambdaResource = {

src/providers/aws/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AWSProvider extends Provider {
6262
const resolvedFuncName = process.env[`FUNCTIONAL_SERVICE_${funcName.toUpperCase()}`] || funcName
6363

6464
const invokeParams = {
65-
FunctionName: resolvedFuncName,
65+
FunctionName: `${process.env.FUNCTIONAL_PROJECTNAME}-${resolvedFuncName}`,
6666
Payload: JSON.stringify(params)
6767
};
6868

test/invoke.tests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { httpTrigger, inject, injectable, param, rest, createParameterDecorator
99

1010
describe('invoke', () => {
1111
const FUNCTIONAL_ENVIRONMENT = 'custom'
12+
const FUNCTIONAL_PROJECTNAME = 'my-test-project'
1213

1314
describe('general', () => {
1415
beforeEach(() => {
@@ -878,9 +879,11 @@ describe('invoke', () => {
878879
describe('aws', () => {
879880
beforeEach(() => {
880881
process.env.FUNCTIONAL_ENVIRONMENT = FUNCTIONAL_ENVIRONMENT
882+
process.env.FUNCTIONAL_PROJECTNAME = FUNCTIONAL_PROJECTNAME
881883
})
882884
afterEach(() => {
883885
delete process.env.FUNCTIONAL_ENVIRONMENT
886+
delete process.env.FUNCTIONAL_PROJECTNAME
884887
removeProvider(FUNCTIONAL_ENVIRONMENT)
885888
})
886889

@@ -891,7 +894,7 @@ describe('invoke', () => {
891894
public async invokeExec(config: any): Promise<any> {
892895
counter++
893896

894-
expect(config).to.have.property('FunctionName', 'A')
897+
expect(config).to.have.property('FunctionName', `my-test-project-A`)
895898
expect(config).to.have.property('Payload', JSON.stringify({ p1: 'p1' }))
896899
}
897900
}

0 commit comments

Comments
 (0)