I am implementing Amazon Web Services in my Symofony 3.4 project but when I trigger my testing url it throws:
Missing required client configuration options:
region: (string) A region configuration value is required.
My region is console is EU(Ireland) and I have checked documentation and put parameter by that.
This is my service.yml
demo_storage:
class: App\Service\S3\S3Service
arguments:
- "test.app" # Name of Bucket
- credentials:
key: "%amazon_key%"
secret: "%amazon_secret%"
region: "eu-west-1"
version: "2006-03-01"
public: true
Related
When I import services in the main configuration:
imports:
- { resource: services/attribute_loaders.yaml }
The services in the included file will be replaced with an autoconfigured version, so I've missed all my configured tags:
services:
App\Infrastructure\Bridge\Doctrine\EventListener\AttributeLoader\OrderAttributeLoader:
autowire: true
tags:
- name: 'doctrine_mongodb.odm.event_listener'
entity: 'App\Infrastructure\Bridge\Doctrine\EventListener\AttributeLoader\OrderAttributeLoader'
event: 'postLoad'
As a workaround, I've excluded my service from autoconfigure.
Is there any way to decompose services into several files?
That's exactly how you do it.
If you are going to use multiple files to configure your services, you simply can't define the same service twice.
Your definitions need to be specific enough so they do not overlap.
If you are going to use broad resource settings, you will need to add all the corresponding excludes so services defined in different files are not defined before it's time:
services:
App\:
resource: '../src/*'
exclude:
- '../src/Infrastructure/Symfony/DependencyInjection'
- '../src/Infrastructure/Symfony/Kernel.php'
- '../src/Tests'
- '../src/Messenger'
Services on src/Messenger, that belong to the App\Messenger namespace, can be defined independently on a different file:
E.g. something like this:
# messenger_services.yaml
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false
App\Messenger\CommandHandler\:
resource: '../../src/Messenger/CommandHandler/*'
tags:
- {name: 'messenger.message_handler', bus: command.bus}
App\Messenger\EventHandler\:
resource: '../../src/Application/EventHandler/*'
tags:
- {name: 'messenger.message_handler', bus: event.bus}
I've upgraded my symfony projet version from 3.3 to 3.4 a few month ago and everything woked find but i recently tried to ad an event listener and then i've got that error
The configuration key "public" cannot be used to define a default value in "/home/pc-dev/Labs/Projets-jebuy/je-buy.com/app/config/services.yml". Allowed keys are "private", "tags", "autowire", "autoconfigure", "bind" in /home
/pc-dev/Labs/Projets-jebuy/je-buy.com/app/config/services.yml (which is being imported from "/home/pc-dev/Labs/Projets-jebuy/je-buy.com/app/config/config.yml").
obviuosly nothing seriuos i edited the default service.yml file from this
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
twig.extension:
class: AppBundle\Twig\Extension\MenuExtension
arguments:
- '#doctrine'
tags:
- {name : twig.extension }
# service.extension:
# class: AdminBundle\DependencyInjection\AdminExtension
# arguments: []
# tags: []
to this (because in symfony 3.4 or 4, all services are by default private)
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
private: true
twig.extension:
class: AppBundle\Twig\Extension\MenuExtension
arguments:
- '#doctrine'
tags:
- {name : twig.extension }
# service.extension:
# class: AdminBundle\DependencyInjection\AdminExtension
# arguments: []
# tags: []
but when i tried to run the server i've now got this error
The service "templating.loader.cache" has a dependency on a non-existent service "templating.loader.wrapped".
and i don't now how to solve it and where is that template.loder.wrapped service.
I have the following configuration in my monolog.yaml file:
monolog:
handlers:
main:
type: stream
path: "php://stdout"
level: debug
channels: ["!event"]
gelf:
type: gelf
publisher:
hostname: mygelfhost.com
port: 12201
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
But it only sends messages to mygelfhost.com using UDP. When I tried to put:
hostname: tcp://mygelfhost.com
I receive the following error:
Failed to create socket-client for udp://tcp://log-dev.hpa.lis-dev.net:12201: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
My goal is to send the logs via TCP to the same host, I have checked the configuration here: https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L25 with no possible solution.
Building off of #Chase's answer:
monolog:
handlers:
gelf:
type: gelf
publisher: my_tcp_gelf_publisher
The difference above is my_tcp_gelf_publisher is a Publisher object, not a Handler object. You want to tell the handler, which publisher to use "my_tcp_gelf_publisher", since that's what's being defined in services.yaml
In services.yaml:
services:
my_tcp_gelf_publisher:
class: Gelf\Publisher
arguments: ["#gelf.tcp_transport"]
gelf.tcp_transport:
class: Gelf\Transport\TcpTransport
arguments:
- "mygelfhost.com" # Hostname
- 12201 #port
This is pretty much the same, except you'll need to put the #gelf.tcp_transport service reference in quotes, otherwise you'll get a scaler error.
A bonus tip, if by chance you decide to configure your transport to use port 12202 (Gelf\Transport\TcpTransport's SSL port) be sure to ensure your endpoint supports ssl and you provide the correctly configured SslOptions object, otherwise use standard port 12201 (or any other port).
You need to specify the transport for Gelf. By default it uses UDP.
monolog:
handlers:
gelf:
type: gelf
id: my_tcp_gelf_publisher
In your services:
services:
my_tcp_gelf_publisher:
class: Gelf\Publisher
arguments: [#gelf.tcp_transport]
gelf.tcp_transport:
class: Gelf\Transport\TcpTransport
arguments:
- "mygelfhost.com" # Hostname
- 12201 #port
Something like this should work, I havent tested the code though. Based on the defining a publisher and the config example from: https://github.com/bzikarsky/gelf-php
I'm on Symfony 4 and I want to create a dedicated channel for many log types:
this is my configuration for channels and handlers:
monolog:
channels: ["channel1", "channel2"]
handlers:
channel1:
level: debug
type: stream
path: "%kernel.logs_dir%/channel1.log"
channels: ["channel"]
channel2:
level: debug
type: stream
path: "%kernel.logs_dir%/channel2.log"
channels: ["channel2"]
Then, in my service to write log, I inject the custom
services:
_defaults:
autowire: true
autoconfigure: true
Infrastructure\Logger\Channel1Logger:
arguments:
- '#monolog.logger.channel1'
Infrastructure\Logger\Channel2Logger:
arguments:
- '#monolog.logger.channel2'
But, all my logs are directly written to the channel "app",
When I debug the container, I see my services listed
What I'm doing wrong?
I found the error. By default, the config/services.yaml will override all configuration from external files. That's why my log continues to be on the default channel (autowiring). To avoid this, you have to exclude the loggers custom files from autowiring
im using symfony2 as framework form my application, i want to connect to my ceph client as it is said in API (same as amazon s3).
composer.json:
"knplabs/knp-gaufrette-bundle": "dev-master",
"aws/aws-sdk-php": "*",
"amazonwebservices/aws-sdk-for-php": "*"
im using gaufrette bundle to manage my filesystem
what i got so far is:
config.yml
mydrive.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
key: %my_drive_s3_key%
secret: %my_drive_s3_secret_key%
region: %my_drive_s3_region%
knp_gaufrette:
adapters:
my_drive_s3_v2:
aws_s3:
service_id: 'mydrive.aws_s3.client'
bucket_name: '%my_drive_s3_bucket_name%'
options:
create: true
directory: '%my_drive_s3_directory%'
filesystems:
user_fs:
adapter: my_drive_s3_v2
alias: my_drive_filesystem
stream_wrapper:
protocol: data
so following the api's this is the way i'm connecting to amazon s3 serwers
but im not using amazon s3 serwers im using my own ceph serwers.
and my question is how i change the host in amazon s3 client ?
now it's like this:
[curl] 56: Problem (2) in the Chunked-Encoded data [url] https://mybucket.s3.amazonaws.com
and i want this
https://mybucket.s3.amazonaws.com to be https://mybucket.s3.custom.com
here is the api i followed: https://github.com/KnpLabs/KnpGaufretteBundle#awss3
Try setting the base_url parameter.
config.yml
mydrive.aws_s3.client:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
-
key: %my_drive_s3_key%
secret: %my_drive_s3_secret_key%
region: %my_drive_s3_region%
base_url: https://mybucket.s3.custom.com
Please check the AWS SDK for PHP User Guide to see all of the client configuration options.