0

I would like to put my Strapi Headless CMS to Heroku and connect it to the AWS S3 server. Because otherwise, Heroku are regularly clearing all my blog posts as well as users.

  • I created AWS S3 bucket, provided Public Read and List access to everything AWS S3 AWS S3
  • set up Cross-origin resource sharing (CORS) to:
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD",
            "POST",
            "PUT"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
  • created a User in IAM (Identity and Access Management) provided him AmazonS3FullAccess get his Access key ID & Secret access key

  • then in my Strapi backend terminal (connected to Heroku) I setup the following:

heroku config:set AWS_ACCESS_KEY_ID=*** AWS_SECRET_ACCESS_KEY=*** 
heroku config:set S3_BUCKET_NAME=mielenyvin
heroku config:set AWS_URL=https://mielenyvin.s3.amazonaws.com/
heroku config:set AWS_S3_REGION_NAME=us-east-2

But nothing happens. All the posts from my database as well as roles and permissions still disappearing from Heroku after couple hours or so. And nothing appearing in my AWS S3 bucket when I am adding a new post.

./config/database.js content:

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'sqlite',
        filename: env('DATABASE_FILENAME', '.tmp/data.db'),
      },
      options: {
        useNullAsDefault: true,
      },
    },
  },
});

./config/env/production/database.js content:

const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: config.host,
      port: config.port,
      database: config.database,
      user: config.user,
      password: config.password,
      ssl: {
        rejectUnauthorized: false
      },
    },
    debug: false,
  },
});
  • "All the posts from my database as well as roles and permissions still disappearing from Heroku after couple hours or so"—as I said when [you posted an earlier, related question](https://stackoverflow.com/q/70282723/354577), you _cannot_ use SQLite on Heroku. Amazon S3 is a different thing, and has nothing to do with your database. _Again_, are you using SQLite? – ChrisGPT was on strike Dec 09 '21 at 16:36
  • You may also have an S3 issue, but that isn't clear. If your database is getting nuked it won't have links to your files anymore. Are you sure the _files_ are actually gone from S3, or is this just a database problem? – ChrisGPT was on strike Dec 09 '21 at 16:37
  • Thank you, Chris! I'm using PostgreSQL. So... that's mean I cannot use my PostgreSQL database together with Heroku? Or I can externally host it somewhere, like I host the pictures on the Cloudinary and still stay on Hiroku? – Dmitry Kotikov Dec 09 '21 at 18:09
  • I also checked Heroku plans, and in Hobby Dev plan for Postgres Extension they have (for free): Row Limit 10,000 Storage Capacity 1 GB Which is enough for my project. https://elements.heroku.com/addons/heroku-postgresql – Dmitry Kotikov Dec 09 '21 at 22:26
  • I understood. This works only during the "Dyno hours" – Dmitry Kotikov Dec 09 '21 at 22:31
  • Are you _entirely sure_ you are using PostgreSQL? The behaviour you describe sounds a _lot_ like what happens if you use SQLite on Heroku. Please [edit] your question and show your `./config/database.js` file (make sure to remove sensitive information like passwords). – ChrisGPT was on strike Dec 09 '21 at 22:34
  • I'm not sure now, I have two files /config/env/production/database.js and /config/database.js – Dmitry Kotikov Dec 10 '21 at 10:56

0 Answers0