Skip to content

Commit

Permalink
fix: firelens configFileValue is optional
Browse files Browse the repository at this point in the history
aws/aws-for-fluent-bit#352

Signed-off-by: Wesley Pettit <wppttt@amazon.com>
  • Loading branch information
PettitWesley committed Jun 2, 2022
1 parent 01711e8 commit 3d5b50b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -1481,7 +1481,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -2446,7 +2446,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -3293,9 +3293,9 @@
}
},
"Parameters": {
"SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/aws-for-fluent-bit/latest"
"Default": "/aws/service/aws-for-fluent-bit/stable"
}
},
"Outputs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@
"data": "nameenvoytoappmesh2767D3E6"
}
],
"/aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
"/aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
{
"type": "aws:cdk:logicalId",
"data": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"data": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
}
],
"/aws-ecs-integ/name-publish-metrics/Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@
],
"essential": true,
"image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"memoryReservation": 50,
"name": "firelens",
Expand Down Expand Up @@ -1536,17 +1536,17 @@
"version": "0.0.0"
}
},
"SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118",
"SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
Expand Down Expand Up @@ -2370,7 +2370,7 @@
],
"essential": true,
"image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"memoryReservation": 50,
"name": "firelens",
Expand Down Expand Up @@ -3889,7 +3889,7 @@
],
"essential": true,
"image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"memoryReservation": 50,
"name": "firelens",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('firelens', () => {
Type: 'fluentbit',
},
Image: {
Ref: 'SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter',
Ref: 'SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter',
},
LogConfiguration: {
LogDriver: 'awslogs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -1615,7 +1615,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -2587,7 +2587,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -3437,9 +3437,9 @@
}
},
"Parameters": {
"SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/aws-for-fluent-bit/latest"
"Default": "/aws/service/aws-for-fluent-bit/stable"
}
},
"Outputs": {
Expand Down
74 changes: 48 additions & 26 deletions packages/@aws-cdk/aws-ecs/lib/firelens-log-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export interface FirelensOptions {

/**
* Custom configuration file, S3 ARN or a file path
* @default - configFileValue is user defined and optional and there is no default
*/
readonly configFileValue: string;
readonly configFileValue?: string;
}

/**
Expand Down Expand Up @@ -109,14 +110,22 @@ export interface FirelensLogRouterDefinitionOptions extends ContainerDefinitionO
function renderFirelensConfig(firelensConfig: FirelensConfig): CfnTaskDefinition.FirelensConfigurationProperty {
if (!firelensConfig.options) {
return { type: firelensConfig.type };
} else if (firelensConfig.options.configFileValue === undefined) {
// config file options must be set together and are optional
return {
type: firelensConfig.type,
options: {
'enable-ecs-log-metadata': firelensConfig.options.enableECSLogMetadata ? 'true' : 'false',
},
};
} else {
// firelensConfig.options.configFileType has been filled with s3 or file type in constructor.
return {
type: firelensConfig.type,
options: {
'enable-ecs-log-metadata': firelensConfig.options.enableECSLogMetadata ? 'true' : 'false',
'config-file-type': firelensConfig.options.configFileType!,
'config-file-value': firelensConfig.options.configFileValue,
'config-file-value': firelensConfig.options.configFileValue!,
},
};
}
Expand Down Expand Up @@ -203,32 +212,45 @@ export class FirelensLogRouter extends ContainerDefinition {
if (options) {
const enableECSLogMetadata = options.enableECSLogMetadata || options.enableECSLogMetadata === undefined;
const configFileType = (options.configFileType === undefined || options.configFileType === FirelensConfigFileType.S3) &&
(cdk.Token.isUnresolved(options.configFileValue) || /arn:aws[a-zA-Z-]*:s3:::.+/.test(options.configFileValue))
(cdk.Token.isUnresolved(options.configFileValue) || /arn:aws[a-zA-Z-]*:s3:::.+/.test(options.configFileValue || ''))
? FirelensConfigFileType.S3 : FirelensConfigFileType.FILE;
this.firelensConfig = {
type: props.firelensConfig.type,
options: {
enableECSLogMetadata,
configFileType,
configFileValue: options.configFileValue,
},
};

// grant s3 access permissions
if (configFileType === FirelensConfigFileType.S3) {
props.taskDefinition.addToExecutionRolePolicy(new iam.PolicyStatement({
actions: [
's3:GetObject',
],
resources: [options.configFileValue],
}));
props.taskDefinition.addToExecutionRolePolicy(new iam.PolicyStatement({
actions: [
's3:GetBucketLocation',
],
resources: [options.configFileValue.split('/')[0]],
}));

if (options.configFileValue != undefined) {
this.firelensConfig = {
type: props.firelensConfig.type,
options: {
enableECSLogMetadata,
configFileType,
configFileValue: options.configFileValue,
},
};
} else {
this.firelensConfig = {
type: props.firelensConfig.type,
options: {
enableECSLogMetadata: enableECSLogMetadata,
},
};
}

if (options.configFileValue != undefined) {
// grant s3 access permissions
if (configFileType === FirelensConfigFileType.S3) {
props.taskDefinition.addToExecutionRolePolicy(new iam.PolicyStatement({
actions: [
's3:GetObject',
],
resources: [options.configFileValue],
}));
props.taskDefinition.addToExecutionRolePolicy(new iam.PolicyStatement({
actions: [
's3:GetBucketLocation',
],
resources: [(options.configFileValue || '').split('/')[0]],
}));
}
}

} else {
this.firelensConfig = props.firelensConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
"Type": "fluentbit"
},
"Image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down Expand Up @@ -627,9 +627,9 @@
}
},
"Parameters": {
"SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/aws-for-fluent-bit/latest"
"Default": "/aws/service/aws-for-fluent-bit/stable"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@
"data": "ServiceD69D759B"
}
],
"/aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
"/aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [
{
"type": "aws:cdk:logicalId",
"data": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"data": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@
{
"essential": true,
"image": {
"Ref": "SsmParameterValueawsserviceawsforfluentbitlatestC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceawsforfluentbitstableC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"memoryReservation": 50,
"name": "log-router",
Expand Down Expand Up @@ -1081,17 +1081,17 @@
"version": "0.0.0"
}
},
"SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--latest:C96584B6-F00A-464E-AD19-53AFF4B05118",
"SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118": {
"id": "SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118",
"path": "aws-ecs-integ/SsmParameterValue:--aws--service--aws-for-fluent-bit--stable:C96584B6-F00A-464E-AD19-53AFF4B05118",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
Expand Down

0 comments on commit 3d5b50b

Please sign in to comment.