I've created a new entity with ResourcesBundle but on the profiler I can't see the Events.
Must I create manualy?
Creating an EventListener for sylius.book.pre_create doesn't do nothing.
Adding Info
Hi anothertime lchrusciel.
This is my configuration for my resource:
dinamic_sylius_post:
resource: |
alias: dinamic.post
path: blog/post
type: sylius.resource
dinamic_sylius_admin_post:
resource: |
alias: dinamic.post
section: admin
templates: SyliusAdminBundle:Crud
except: ['show', 'delete']
redirect: index
grid: dinamic_sylius_blog_post
type: sylius.resource
prefix: admin/
And on my bundle config I have this:
sylius_resource:
resources:
dinamic.post:
classes:
model: Dinamic\Bundle\SyliusBlogBundle\Entity\Post
form:
default: Dinamic\Bundle\SyliusBlogBundle\Form\PostType
What I'm doing wrong then?
If it is your custom resource you should look for app.book.pre_create event.
As you can see here event name depends on application name which is sylius for predefined Sylius resources, but if you defined your own, it usually app.
If you have followed Sylius docs about using ResourceBundle with your own resources you have found following config:
sylius_resource:
resources:
app.book:
classes:
model: AppBundle\Entity\Book
So important part of this config is an alias of resource app.book. Dot split alias to application name(app) and resource name(book).
Same rules apply to crud generation config:
app_book:
resource: |
alias: app.book
type: sylius.resource_api
Using app as a application name is Sylius recommendation, but you can arbitrary choose any other.
Edit
In your example this is an important part:
sylius_resource:
resources:
dinamic.post:
classes:
According to it, dinamic is an application name, and post is a resource name. So the following events should be triggered:
dinamic.post.pre_create
dinamic.post.post_create
dinamic.post.pre_update
dinamic.post.post_update
dinamic.post.pre_delete
dinamic.post.post_delete
Related
I'm learning how to use swagger/openapi, and starting to use swagger-routes-express package to simplify the association of routes to OpenAPI definition. One of the things I'm confused about is the servers config. For example, here's an excerpt from the swagger-routes-express example for OpenAPI Version 3 example:
paths:
/ping:
get:
tags:
- root
summary: Get Server Information
description: Returns information about the server
operationId: ping
responses:
'200':
description: success
content:
application/json:
schema:
$ref: '#/components/schemas/ServerInfo'
servers:
- url: /api/v1
Here we've got a get path of /ping. It seems like this gets added onto the end of the server's url:
/api/v1/ping
I understand that multiple servers can be listed under the servers section, and you might want to do that for development, testing, and production. Based on my testing, it seems like the route path that's created is based on the first server entry. Is that correct? How will this work when multiple servers are defined?
Is it possible to have lambda function with different custom domain than others; In servlerless lambda project, I need to have one lambda to use different custom domain than other lambdas. for example
userNotification --> dev.xyz.com/users
all others
getProducts --> dev.abc.com/products
I tried using custom domain as following but it did not work.
userNotification:
handler: src/index.handler
events:
- http:
method: get
path: /userNotification
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- If-Match
- If-None-Match
# override default customDomain
customDomain:
domainName: 'dev.xyz-comm-sanbox.com'
basePath: dev-newbank
stage: dev
createRoute53Record: true
In serverless.yml, I'm using custom domains as, this work fine but then i have single customDomains for all lambdas funcrion. I need to have one lambda to use different customDomain than others;
custom:
customDomain:
basePath: dev-newbank
domainName: 'dev.abc.com'
stage: 'dev'
createRoute53Record: true
endpointType: regional
securityPolicy: tls_1_2
I think you would have to have 2 different serverless.ymls, 1 for managing your /products path and one for /users. Then you could specify different domains for each. Since underneath it all API Gateway only supports custom domains on the API, not on individual endpoints in the API, you would have to split your lambdas up
In OpenAPI 3, is it possible to define a SecurityScheme at global level but then override it at certain endpoints to not use security (for public accessible endpoints)?
For example (taken from https://swagger.io/docs/specification/authentication/bearer-authentication/)
openapi: 3.0.0
...
# 1) Define the security scheme type (HTTP bearer)
components:
securitySchemes:
bearerAuth: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
- bearerAuth: [] # use the same name as above
And then make a given endpoint publicly accessible (unprotected)
paths:
/unprotected/path:
get:
security: []
Or should this be done in another way?
Update this question was marked as duplicate but the other question handles about Swagger 2.x and since syntax is different, I think this question and answers should remain.
You can indeed override security on a path bases in OA3 as follows:
paths:
/unprotected/path:
get:
security: []
I'm currently working on expanding this repo. It contains source code to deploy a sapper/svelte webapp with the Serverless Framework to AWS. I'm thinking about how to expand the serverless.yml to include Route53 DNS routing to Cloudfront, but I can't seem to wrap my head around it. The serverless-domain-manager plugin seems to be designed for Route53 to API Gateway routing, but I'm deploying my app only with Cloudfront, an S3 bucket and an Lambda#Edge handler server-side-rendering the application.
I've done something similar here.
I've trimmed the serverless.yml for the relevant parts:
WebAppCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
DependsOn:
- WebAppS3Bucket
Properties:
DistributionConfig:
### content trimmed
Aliases:
- 'www.example.com'
### content trimmed
ViewerCertificate:
AcmCertificateArn: 'CertificateArn' # in the linked repo I'm using a plugin to auto generate the certificate
SslSupportMethod: sni-only
WebsiteDNSName:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: 'HostedZoneId' # Taken from the AWS Console
RecordSets:
- Name: 'www.example.com'
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: !GetAtt [WebAppCloudFrontDistribution, DomainName]
EvaluateTargetHealth: false
I am new to serverless application. I followed the aws tutorial to build a simple nodejs serverless app with codestar and lambda.
However, imagine this node app does multiple things. In consequence, it has mutiple functions inside index.js, one for functionnality A, one for functionnality B, etc (for example).
Do I have to attach multiple lambda expressions, one for each functionality, to this codestar project?
Question: Do I have to attach multiple lambda expressions, one for each functionality, to this codestar project?
Answer: Yes
AWS CodeStar Project Details:
AWS Code star project contains below file structure(reference link):
README.md - this file
buildspec.yml - this file is used by AWS CodeBuild to package your service for deployment to AWS Lambda
app.js - this file contains the sample Node.js code for the web service
index.js - this file contains the AWS Lambda handler code
template.yml - this file contains the Serverless Application Model (SAM) used by AWS Cloudformation to deploy your service to AWS Lambda and Amazon API Gateway.
Assume you have the template.yml file like below:
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar
Resources:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Handler: index.first_handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /first
Method: get
HelloWorld2:
Type: AWS::Serverless::Function
Properties:
Handler: index.second_handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /second
Method: get
Notice that, in above tamplate.yml file specified "HelloWorld" and "HelloWorld2" configurations.
HelloWorld configuration contains "Handler" value as "index.first_handler" meaning that "index" is the filename of index.js and first_handler is the method in index.js file.
Likewise, HelloWorld2 configuration contains "Handler" value as "index.second_handler" meaning that "index" is the filename of index.js and second_handler is the method in index.js file.
Conclusion:
You can specify any number of lambda functions in your index.js (whatever.js) file. Only you need to specify the proper Handler to identify the app your lambda function.
Hope this is the answer to your question. Feel free to ask doubts, if you have!
you don't need multiple handler functions (index.js) and you cannot have multiple handler functions. If the different functionality is doing the logically separated job then you can add multiple JS files and write functions there but you should refer that to your handler function (index.js). Alternatively, you can write functionality in index.js itself but better idea and clean code is to separate logically different functionality to another file and refer it