How to implement Log4j2 custom layout yaml configuration - log4j2

I am using custom layout for log4j2 framework. How to specify custom layout in log4j2 yaml configuration file ?
The sample I tried is given below. This does not work at the moment saying invalid element 'layout'.
Configutation:
status: warn
packages: uk.co.logging.layout
Properties:
Property:
name: logging.dir
value: ./default_log_dir/
Property:
name: service.name
value: default
Appenders:
Console:
name: CONSOLE
layout: ConnectJsonLayout
policies:
TimeBasedTriggeringPolicy:
interval: 1
modulate: true
SizeBasedTriggeringPolicy:
size: 250MB
RollingFile:
- name: APPLICATION
fileName: ${logging.dir}/${service.name}.log
filePattern: ${logging.dir}/${date:yyyy-MM}/${service.name}-%d{yyyy-MM-dd}-%i.log.gz
layout: ConnectJsonLayout
policies:
TimeBasedTriggeringPolicy:
interval: 1
modulate: true
SizeBasedTriggeringPolicy:
size: 250MB
Loggers:
Root:
level: error
AppenderRef:
- ref: CONSOLE
- ref: APPLICATION
Logger:
- name: uk.co.xxx
additivity: false
level: debug
AppenderRef:
- ref: CONSOLE
- ref: APPLICATION
Kind Regards,
Kiran

Configutation:
status: warn
packages: uk.co.logging.layout
Properties:
Property:
name: logging.dir
value: ./default_log_dir/
Property:
name: service.name
value: default
Appenders:
Console:
name: CONSOLE
ConnectJsonLayout: {}
Loggers:
Root:
level: error
AppenderRef:
- ref: CONSOLE

Related

How to access AWS SAM Mapping in swagger.yaml / openapi.yaml files

I have declared a mapping named StageMap in my sam.yaml file:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
ProjectName:
Type: String
SubProjectName:
Type: String
Stage:
Type: String
AllowedValues:
- dev
- test
- preprod
- prod
...
Mappings:
StageMap:
dev:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations
test:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-test-AuthorizerFunction-UQ1EQ2SP5W6G/invocations
preprod:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-preprod-AuthorizerFunction-UQ1W6EQ2SP5G/invocations
prod:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-prod-AuthorizerFunction-5STBUB61RR2YJ/invocations
I would like to use this mapping in my swagger.yaml I have tried the following:
...
x-amazon-apigateway-authorizer:
type: request
authorizerUri:
Fn::FindInMap:
- 'StageMap'
- Ref: 'Stage'
- 'AuthorizerArn
I also tried this solution but I got an error Every Mappings attribute must be a String or a List.
Can you please let me know how to access one of the values in the mapping in the swagger.yaml? Thanks!
I found the following in the AWS SAM docs:
You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section.
So I changed:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations
For:
AuthorizerFunctionName: auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6
And in the swagger.yaml I used the following:
x-amazon-apigateway-authorizer:
type: request
authorizerUri:
Fn::Sub:
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AuthorizerFunctionName}/invocations
- AuthorizerFunctionName:
Fn::FindInMap:
- 'StageMap'
- Ref: 'Stage'
- 'AuthorizerFunctionName'

serverless framework with aws import function returns 404

I have two serverless app which are sharing the same custom authorizer. Suddenly the import function in the second serverless.yml file stopped working.
The app is based on https://github.com/medwig/serverless-shared-authorizer
gateway.serverless
service: authorizer-stack
provider:
name: aws
runtime: nodejs12.x
region: ap-south-1
profile: xxx-dev
functions:
authorizer:
handler: handler.auth
test:
handler: handler.privateEndpoint
events:
- http:
path: /api/test
method: get
authorizer:
type: CUSTOM
authorizerId:
Ref: Authorizer
test2:
handler: handler.publicEndpoint
events:
- http:
path: /api/test/public
method: get
resources:
Resources:
AuthorizerPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::GetAtt: AuthorizerLambdaFunction.Arn
Action: lambda:InvokeFunction
Principal:
Fn::Join: ["",["apigateway.", { Ref: "AWS::URLSuffix"}]]
Authorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: ${self:provider.stage}-Authorizer
RestApiId: { "Ref" : "ApiGatewayRestApi" }
Type: TOKEN
IdentitySource: method.request.header.Authorization
AuthorizerResultTtlInSeconds: 300
AuthorizerUri:
Fn::Join:
- ''
-
- 'arn:aws:apigateway:'
- Ref: "AWS::Region"
- ':lambda:path/2015-03-31/functions/'
- Fn::GetAtt: "AuthorizerLambdaFunction.Arn"
- "/invocations"
Outputs:
AuthorizerId:
Value:
Ref: Authorizer
Export:
Name: authorizerId
apiGatewayRestApiId:
Value:
Ref: ApiGatewayRestApi
Export:
Name: restApiId
apiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
Export:
Name: rootResourceId
products serverless
service: products-list
provider:
name: aws
runtime: nodejs12.x
region: ap-south-1
profile: xxx-dev
apiGateway:
restApiId:
Fn::ImportValue: authorizer-stack-dev-restApiId
restApiRootResourceId:
Fn::ImportValue: authorizer-stack-dev-rootResourceId
functions:
get-products:
handler: handler.getProducts
events:
- http:
path: /api/products
method: get
authorizer:
type: CUSTOM
authorizerId:
Fn::ImportValue: authorizer-stack-dev-authorizerId
I am getting the following errors at random
An error occurred: products-list-dev - No export named authorizer-stack-dev-restApiId found.
An error occurred: products-list-dev - No export named authorizer-stack-dev-rootResourceId found.
An error occurred: products-list-dev - No export named authorizer-stack-dev-authorizerId found.
What am I missing here?
serverless -v
Framework Core: 1.74.1
Plugin: 3.6.15
SDK: 2.3.1
Components: 2.31.10
From the shared authorizers I have configured in the past it is not necessary to go to the effort you have undergone. The documentation on the Serverless Framework site has a much simpler setup to achieve a shared authoriser and I will always go with the simplest solution possible: https://www.serverless.com/framework/docs/providers/aws/events/apigateway#share-authorizer

Conditional resource in serverless

I would like to add an AWS resource conditionally based on presence of an env var. I tried serverless-cloudformation-parameter-setter but I get a generic error on deployment and I don't see what I need to do to fix it
I'm trying to deploy a simple lambda + SQS stack and if a env var is defined also subscribe the queue to the topic denoted by the env var - or if the var is not defined then not do that part at all, just the lambda and the queue
This is what I tried:
plugins:
- serverless-cloudformation-parameter-setter
provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
functions:
update:
handler: index.update
events:
- sqs:
arn:
Fn::GetAtt:
- Queue
- Arn
custom:
cf-parameters:
SourceTopicArn: "${env:UPDATE_SNS_ARN}"
resources:
Parameters:
SourceTopicArn:
Type: string
Resources:
Queue:
Type: "AWS::SQS::Queue"
Subscription:
Type: "AWS::SNS::Subscription"
Condition: SourceTopicArn
Properties:
TopicArn:
Ref: SourceTopicArn
Endpoint:
Ref: Queue
The error I receive is: The CloudFormation template is invalid: Template format error: Unrecognized parameter type: string
If I remove all the parameter stuff it works fine
The Type has to be String, not string. See the supported parameter data types section in the docs.

windows heat template user_data can not work

I am new to CloudbaseInit. I have setup a image with CloudbaseInit,and can build the machine with new password and expand hdd size all ok (using command :nova boot). But I want to use heat stack-create with a heat template file
heat_template_version: 2013-05-23
description: dtb test hottest,for test add parameters.
parameters:
flavor:
type: string
label: paasflavor
description: paasflavor flavor to be used
default: c1m2h90
availability_zone:
type: string
description: The Availability Zone to launch the instance.
default: nova
name:
type: string
description: name of host.
resources:
server1_port1:
type: OS::Neutron::Port
properties:
network_id: 70c1faf0-51f6-4cb9-b324-7bc2cc6fab5b
server1:
type: OS::Nova::Server
properties:
name: { get_param: name }
image: template_win2008
flavor: { get_param: flavor }
availability_zone: { get_param: availability_zone }
networks:
- port: { get_resource: server1_port1 }
user_data:
echo 11 > \"c:\\yp\\333"\n,
outputs:
server1_ip:
description: Private IP address of server1
value: { get_attr: [ server1, first_address ] }
Machine builds ok. When I login into it, and go to c:\yp, I find nothing. I think user_data is wrong, and command not work. I have tried several other ways for writing user_data part, but all failed. I never build windows machine with heat template.
Add pipe(|) after user_data:
user_data: |

How to override an attribute for a specific job when working with Jenkins Job Builder (JJB)

We have got a Jenkins setup (at the moment not managed with the Jenkins Job Builder) where every web project has 5 very similar Jenkins jobs. This is a simplified Jenkins Job Builder yaml file which could work for our needs:
- defaults:
name: global
project-type: 'freestyle'
disabled: false
buildTargets: 'build'
- job-template:
name: '{jobNameFirstSegment}-{jobNameSecondSegment}'
defaults: global
builders:
- ant:
targets: '{buildTargets}'
buildfile: 'build.xml'
- project:
name: lorem
jobNameFirstSegment:
- foo:
displayNameFirstSegment: 'Foo'
urlGitRepository: 'git#bitbucket.org:mycompany/foo.git'
- bar:
displayNameFirstSegment: 'Bar'
urlGitRepository: 'git#bitbucket.org:mycompany/bar.git'
- baz:
displayNameFirstSegment: 'Baz'
urlGitRepository: 'git#bitbucket.org:mycompany/baz.git'
jobNameSecondSegment:
- lorem:
buildTargets: 'build-lorem'
- ipsum:
buildTargets: 'build-ipsum'
- dolor:
buildTargets: 'build-dolor'
- sit:
buildTargets: 'build-sit'
- amet:
buildTargets: 'build-amet'
jobs:
- '{jobNameFirstSegment}-{jobNameSecondSegment}'
This yaml file results in 15 Jenkins jobs - all are NOT disabled:
foo-lorem
foo-ipsum
foo-dolor
foo-sit
foo-amet
bar-lorem
bar-ipsum
bar-dolor
bar-sit
bar-amet
baz-lorem
baz-ipsum
baz-dolor
baz-sit
baz-amet
Is it possible with this kind of setup to disable a specific Jenkins job? I could not find out how to override the "disabled" attribute for e.g. the Jenkins job "foo-lorem". How can this be achieved?
Infact we would need to have the possibility to be able to override any attribute of any Jenkins job if needed. Is this doable? How?
In the job template, you want to add a disabled property which takes its value from a parameter. Parameters default value can be set at the defaults and project level. So in theory you could pass the disabled value at the job level:
- defaults:
name: global
disabled: false
- job-template:
name: 'build-{name}'
defaults: global
disabled: '{obj:disabled}'
- project:
name: myproject
jobs:
- 'build-{name}'
- project:
name: mydeadproject
jobs:
- 'build-{name}':
disabled: true
Note obj: prefix is to pass the boolean as is. Turns out there is an issue in JJB specific to the disabled parameter, so you need to use a different variable (I named it prevent_run below):
- defaults:
name: global
prevent_run: false
- job-template:
name: 'build-{name}'
defaults: global
disabled: '{obj:prevent_run}'
- project:
name: myproject
jobs:
- 'build-{name}'
- project:
name: mydeadproject
jobs:
- 'build-{name}':
prevent_run: true
In the global default, the variable prevent_run is set to false and is passed to projects and job templates. For the last job, a more specific value is passed to the mydeadproject. The snippet above generates two jobs:
build-mydeadproject disabled
build-myproject enabled
You can reuse the same trick in your example template:
--- reference.yaml 2015-09-08 09:27:56.000000000 +0200
+++ foo.yaml 2015-09-08 10:02:38.000000000 +0200
## -1,11 +1,13 ##
- defaults:
name: global
project-type: 'freestyle'
- disabled: false
+ prevent_run: false
buildTargets: 'build'
+
- job-template:
name: '{jobNameFirstSegment}-{jobNameSecondSegment}'
defaults: global
+ disabled: '{obj:prevent_run}'
builders:
- ant:
You can then pass prevent_run: true on a per job basis:
- project:
name: lorem
jobNameFirstSegment:
- foo:
displayNameFirstSegment: 'Foo'
urlGitRepository: 'git#bitbucket.org:mycompany/foo.git'
prevent_run: true
That disable all jobs having foo for the value of jobNameFirstSegment. I. e. it disables the jobs:
foo-amet
foo-dolor
foo-ipsum
foo-lorem
foo-sit
When a project is realized, a cartesian products of the variables is created to generate the jobs. There is no way here to pass a parameter to a specific couple of values.

Resources