aws-samples / cdk-serverless-lamp

A JSII construct lib to build AWS Serverless LAMP with AWS CDK
Apache License 2.0
65 stars 16 forks source link

/opt/bin/php: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory #419

Closed dannysteenman closed 2 years ago

dannysteenman commented 3 years ago

I've followed the steps described in the blog post: https://aws.amazon.com/blogs/compute/introducing-the-cdk-construct-library-for-the-serverless-lamp-stack/

When I try to access the API GW URL that's provided in the browser I'm immediately welcomed by:

{"message":"Internal Server Error"} 

In CloudWatch logs I see the following error message:

/opt/bin/php: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

The lambda is deployed in Frankfurt (eu-central-1):

    new ServerlessLaravel(this, 'ServerlessLaravel', {
      brefLayerVersion: 'arn:aws:lambda:eu-central-1:209497400698:layer:php-74-fpm:12',
      laravelPath: path.join(__dirname, '../../../assets/laravel-codebase'),
      vpc,
      databaseConfig: {
        writerEndpoint: db.rdsProxy!.endpoint,
      },
    });

The local environment is broken as well and returns a:

File not found.

docker logs for image: bref/fpm-dev-gateway:

2021/09/30 12:50:36 [error] 10#10: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.20.0.1, server: php-docker.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.20.0.2:9001", host: "localhost:8000"
dannysteenman commented 3 years ago

Update: I've updated the layer to v32 (latest): https://bref.sh/docs/runtimes/#layer-version-

Now I'm receiving the following error:

PHP Warning:  require(/var/task/vendor/autoload.php): failed to open stream: No such file or directory in /opt/bootstrap on line 25
PHP Fatal error:  require(): Failed opening required '/var/task/vendor/autoload.php' (include_path='.:/opt/bref/lib/php') in /opt/bootstrap on line 25
dannysteenman commented 3 years ago

Update 2, I got it fixed 🎉: I had to make some adjustments in the docker installation steps, this are the original steps:

docker run --rm -it --volume $PWD:/app composer create-project --prefer-dist laravel/laravel assets/laravel-codebase

cd codebase

docker run --rm -it --volume $PWD:/app composer require bref/bref bref/laravel-bridge

When you run the second docker command, you;ll get the following issue:

aws-cdk-datingleads-poc/codebase on  main [?] via  v16.10.0 via 🐘 v7.3.29 on  datingleads-acc (eu-central-1)
✦ ➜ docker run --rm -it --volume $PWD:/app composer require bref/bref bref/laravel-bridge
Using version ^1.3 for bref/bref
Using version ^1.1 for bref/laravel-bridge
./composer.json has been updated
Running composer update bref/bref bref/laravel-bridge
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - aws/aws-sdk-php[3.134.0, ..., 3.173.19] require guzzlehttp/psr7 ^1.4.1 -> found guzzlehttp/psr7[1.4.1, ..., 1.x-dev] but the package is fixed to 2.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - aws/aws-sdk-php[3.173.20, ..., 3.195.2] require guzzlehttp/psr7 ^1.7.0 -> found guzzlehttp/psr7[1.7.0, ..., 1.x-dev] but the package is fixed to 2.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - bref/laravel-bridge 1.1.0 requires aws/aws-sdk-php ^3.134 -> satisfiable by aws/aws-sdk-php[3.134.0, ..., 3.195.2].
    - Root composer.json requires bref/laravel-bridge ^1.1 -> satisfiable by bref/laravel-bridge[1.1.0].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Then I tried with an additional argument --with-all-dependencies:

aws-cdk-datingleads-poc/codebase on  main [?] via  v16.10.0 via 🐘 v7.3.29 on  datingleads-acc (eu-central-1) took 2s
✦ ✗ docker run --rm -it --volume $PWD:/app composer require bref/bref bref/laravel-bridge --with-all-dependencies
Using version ^1.3 for bref/bref
Using version ^1.1 for bref/laravel-bridge
./composer.json has been updated
Running composer update bref/bref bref/laravel-bridge --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires laravel/framework ^8.54, found laravel/framework[v8.54.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

To fix 👆 that issue I had to modify the composer.lock file and remove:

        {
            "name": "laravel/framework",
            "version": "v8.62.0",
            "source": {
                "type": "git",
                "url": "https://github.com/laravel/framework.git",
                "reference": "60a7e00488167ce2babf3a2aeb3677e48aaf39be"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/laravel/framework/zipball/60a7e00488167ce2babf3a2aeb3677e48aaf39be",
                "reference": "60a7e00488167ce2babf3a2aeb3677e48aaf39be",
                "shasum": ""
            },
            "require": {
                "doctrine/inflector": "^1.4|^2.0",
                "dragonmantank/cron-expression": "^3.0.2",
                "egulias/email-validator": "^2.1.10",
                "ext-json": "*",
                "ext-mbstring": "*",
                "ext-openssl": "*",
                "laravel/serializable-closure": "^1.0",
                "league/commonmark": "^1.3|^2.0.2",
                "league/flysystem": "^1.1",
                "monolog/monolog": "^2.0",
                "nesbot/carbon": "^2.31",
                "opis/closure": "^3.6",
                "php": "^7.3|^8.0",
                "psr/container": "^1.0",
                "psr/log": "^1.0 || ^2.0",
                "psr/simple-cache": "^1.0",
                "ramsey/uuid": "^4.2.2",
                "swiftmailer/swiftmailer": "^6.0",
                "symfony/console": "^5.1.4",
                "symfony/error-handler": "^5.1.4",
                "symfony/finder": "^5.1.4",
                "symfony/http-foundation": "^5.1.4",
                "symfony/http-kernel": "^5.1.4",
                "symfony/mime": "^5.1.4",
                "symfony/process": "^5.1.4",
                "symfony/routing": "^5.1.4",
                "symfony/var-dumper": "^5.1.4",
                "tijsverkoyen/css-to-inline-styles": "^2.2.2",
                "vlucas/phpdotenv": "^5.2",
                "voku/portable-ascii": "^1.4.8"
            },
            "conflict": {
                "tightenco/collect": "<5.5.33"
            },
            "provide": {
                "psr/container-implementation": "1.0",
                "psr/simple-cache-implementation": "1.0"
            },
            "replace": {
                "illuminate/auth": "self.version",
                "illuminate/broadcasting": "self.version",
                "illuminate/bus": "self.version",
                "illuminate/cache": "self.version",
                "illuminate/collections": "self.version",
                "illuminate/config": "self.version",
                "illuminate/console": "self.version",
                "illuminate/container": "self.version",
                "illuminate/contracts": "self.version",
                "illuminate/cookie": "self.version",
                "illuminate/database": "self.version",
                "illuminate/encryption": "self.version",
                "illuminate/events": "self.version",
                "illuminate/filesystem": "self.version",
                "illuminate/hashing": "self.version",
                "illuminate/http": "self.version",
                "illuminate/log": "self.version",
                "illuminate/macroable": "self.version",
                "illuminate/mail": "self.version",
                "illuminate/notifications": "self.version",
                "illuminate/pagination": "self.version",
                "illuminate/pipeline": "self.version",
                "illuminate/queue": "self.version",
                "illuminate/redis": "self.version",
                "illuminate/routing": "self.version",
                "illuminate/session": "self.version",
                "illuminate/support": "self.version",
                "illuminate/testing": "self.version",
                "illuminate/translation": "self.version",
                "illuminate/validation": "self.version",
                "illuminate/view": "self.version"
            },
            "require-dev": {
                "aws/aws-sdk-php": "^3.189.0",
                "doctrine/dbal": "^2.13.3|^3.1.2",
                "filp/whoops": "^2.8",
                "guzzlehttp/guzzle": "^6.5.5|^7.0.1",
                "league/flysystem-cached-adapter": "^1.0",
                "mockery/mockery": "^1.4.4",
                "orchestra/testbench-core": "^6.23",
                "pda/pheanstalk": "^4.0",
                "phpunit/phpunit": "^8.5.19|^9.5.8",
                "predis/predis": "^1.1.2",
                "symfony/cache": "^5.1.4"
            },
            "suggest": {
                "aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.189.0).",
                "brianium/paratest": "Required to run tests in parallel (^6.0).",
                "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.13.3|^3.1.2).",
                "ext-ftp": "Required to use the Flysystem FTP driver.",
                "ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().",
                "ext-memcached": "Required to use the memcache cache driver.",
                "ext-pcntl": "Required to use all features of the queue worker.",
                "ext-posix": "Required to use all features of the queue worker.",
                "ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).",
                "fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).",
                "filp/whoops": "Required for friendly error pages in development (^2.8).",
                "guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.5.5|^7.0.1).",
                "laravel/tinker": "Required to use the tinker console command (^2.0).",
                "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
                "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
                "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
                "mockery/mockery": "Required to use mocking (^1.4.4).",
                "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
                "pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).",
                "phpunit/phpunit": "Required to use assertions and run tests (^8.5.19|^9.5.8).",
                "predis/predis": "Required to use the predis connector (^1.1.2).",
                "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
                "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0|^6.0).",
                "symfony/cache": "Required to PSR-6 cache bridge (^5.1.4).",
                "symfony/filesystem": "Required to enable support for relative symbolic links (^5.1.4).",
                "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).",
                "wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)."
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "8.x-dev"
                }
            },
            "autoload": {
                "files": [
                    "src/Illuminate/Collections/helpers.php",
                    "src/Illuminate/Events/functions.php",
                    "src/Illuminate/Foundation/helpers.php",
                    "src/Illuminate/Support/helpers.php"
                ],
                "psr-4": {
                    "Illuminate\\": "src/Illuminate/",
                    "Illuminate\\Support\\": [
                        "src/Illuminate/Macroable/",
                        "src/Illuminate/Collections/"
                    ]
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Taylor Otwell",
                    "email": "taylor@laravel.com"
                }
            ],
            "description": "The Laravel Framework.",
            "homepage": "https://laravel.com",
            "keywords": [
                "framework",
                "laravel"
            ],
            "support": {
                "issues": "https://github.com/laravel/framework/issues",
                "source": "https://github.com/laravel/framework"
            },
            "time": "2021-09-28T13:30:25+00:00"
        },

and then run the docker command again:

docker run --rm -it --volume $PWD:/app composer require bref/bref bref/laravel-bridge --with-all-dependencies

After deploying the changes to lambda I got the following error in CW logs:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.24. in /var/task/vendor/composer/platform_check.php on line 24

To fix this I had to update the lambda layer to:

arn:aws:lambda:eu-central-1:209497400698:layer:php-80-fpm:21

And now it works again 🎉

Screen Shot 2021-09-30 at 16 12 45
github-actions[bot] commented 3 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

github-actions[bot] commented 2 years ago

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen.