Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid Log Role Creation when roleArn is proivded #624

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,45 @@ describe('Api', () => {
}
`);
});

it('should compile CloudWatch Resources without additional IAM Role when logging roleARN is provided', () => {
const api = new Api(
given.appSyncConfig({
logging: {
level: 'ERROR',
retentionInDays: 14,
enabled: true,
roleArn: 'arn:',
},
}),
plugin,
);

expect(api.compileCloudWatchLogGroup()).toMatchInlineSnapshot(`
Object {
"GraphQlApiLogGroup": Object {
"Properties": Object {
"LogGroupName": Object {
"Fn::Join": Array [
"/",
Array [
"/aws/appsync/apis",
Object {
"Fn::GetAtt": Array [
"GraphQlApi",
"ApiId",
],
},
],
],
},
"RetentionInDays": 14,
},
"Type": "AWS::Logs::LogGroup",
},
}
`);
});
});

describe('apiKeys', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/resources/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ export class Api {
}

const logGroupLogicalId = this.naming.getLogGroupLogicalId();
const roleLogicalId = this.naming.getLogGroupRoleLogicalId();
const policyLogicalId = this.naming.getLogGroupPolicyLogicalId();
const apiLogicalId = this.naming.getApiLogicalId();

return {
const logGroupCF = {
[logGroupLogicalId]: {
Type: 'AWS::Logs::LogGroup',
Properties: {
Expand All @@ -137,6 +135,15 @@ export class Api {
this.plugin.serverless.service.provider.logRetentionInDays,
},
},
};

if (this.config.logging.roleArn) return logGroupCF;

const roleLogicalId = this.naming.getLogGroupRoleLogicalId();
const policyLogicalId = this.naming.getLogGroupPolicyLogicalId();

return {
...logGroupCF,
[policyLogicalId]: {
Type: 'AWS::IAM::Policy',
Properties: {
Expand Down