Yii2 for serverless or Yii2 for Rest Only?

With AWS Lambda now allow custom runtimes it’s possible to run yii2 via API Gateway and Lambda if you wanted to run a serverless Rest API via Yii2. We have a test case setup and running. Works great. I plan on doing a Medium Article once we get to an acceptance point. However the problem we’re running into is the size of the yii2 project. Just the project and composer itself leaves little room for a project code and resources.

Lambda has strict size requirements and looking at the yii2 folder there’s a lot of things related to the frontend. So the question we have is there a stand way to only require “certain” parts of yii2 or does there already existing port of yii2 that is designed specifically for a rest service ie without all the widgets and things for the frontend? I searched but couldn’t find one.

Anyhow, this is just a test case. It may prove to fruitless simply due to lambda size limits but we can say yii2 can and will run in a serverless environment just fine. Whether you have enough resources left over to build a full project is questionable.

Thanks for any of the input

1 Like

Take a look at this meta package that @CeBe prepared https://github.com/cebe/assetfree-yii2
Thanks to this you can get rid of all the assets packages. Unfortunately widget classes come with the core so you can not remove it that easy.

Thanks @Bizley. We’re already using that and it helped a lot. I didn’t know if there was a even more “bare-bone” version of yii2. Again no biggie, we’re just exploring options as we’re planning a move to serverless environments. Right now everything is Yii2 of course with Bootstrap 3.3.7 frontend. We’re planning on moving to VueJS for the frontend and exploring backend options. Currently all of our code is in Yii2 so obviously the “easy” thing would be a lift and shift move to API Gateway and using Lambda to invoke the Controller, keep it simple but we’re over the 250mb function limit. One option is making a single Controller-Active Record Model its own function.

Like I said right now we’re tasked with exploring options. I’d like to stay with Yii because we totally love it but sometimes all good things must come to an end…but maybe not yet :wink: Thanks for the suggestion.

It would be helpful if you can write medium articles about yii2 with aws lambda, bref.sh, aws batch, aws beanstalk …etc
We are developers expecting kind of articles. getting stuck at that points

@jomonjohnson, we’re currently using serverless and bref.sh. The serverless yml handles our cloudformation templates. Let me clean some stuff up and I’ll share an example repo in a couple days. Like I said though, you’ll hit the 250mb function limit rather quickly so we may look at beanstalk next. The thing we wanted to do what get to a pay as you visit model. IE, we host our frontend in S3, pay for storage, but as far as the backend, you only pay for API gateway and lambda when someone visits. If usage is up we pay more but if usage is down we pay less or nothing at all. That way our bills can scale with our business better.

There are a lot good things coming in Yii 3 so don’t say goodbye to Yii yet :wink:

1 Like

@Rjgoolsby, were you able to put together an example repo or an article describing your work with Yii and Lambda? I would be grateful for any more details you could share.

@tyler we did!!! However I never setup a boilerplate for others. We’re currently using it in a couple projects. We have to be careful about the vendors folder but it’s possible. Hopefully when Yii3 matures we’ll move to yii3 and remove much of the unnecessary “fluff”. Give me the weekend and I’ll create a boilerplate in Github and share back on Monday

@Bizley Hey I know it’s been a year and I was curious about yii3. Has it progressed? I never see or hear anything about it. Even https://www.yiiframework.com/ has no mentions of yii3. Just curious of the status. Did it stall and become abandoned or just taking time?

Of course not! It’s being actively developed non-stop. I don’t know the details because I’m not participating, I’m pretty sure @samdark can put more light on it. Anyway there is periodic info stated here https://opencollective.com/yiisoft/updates/yii-news-2020-issue-6 (latest issue).

As @Bizley said, it is actively developed. Our next goal is putting alpha together. Overall, it works already. Starting point is github.com/yiisoft/app, docs are at github.com/yiisoft/docs.

1 Like