You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Amazon EC2实例配置邮件适配器实现应用密码重置

Hey Adam, let’s walk through each of your questions step by step to get your Parse Server email setup and AWS deployment sorted out:

Core Questions & Answers

1. Is your current index.js code enough to create the email adapter?

Almost, but it’s missing two critical pieces:

  • You need to import the Parse Server module (covered in question 3) so Node.js recognizes the ParseServer class.
  • You must install the parse-server-simple-mailgun-adapter dependency in your project (we’ll cover how to include this in your deployment package later).

The adapter configuration itself looks correct once those gaps are filled—just be sure to replace placeholder values like 'etc', 'parse@example.com', and 'key-mykey' with your actual Mailgun and app details.

2. Can you upload text files created in Sublime Text?

Absolutely! Sublime Text saves plain, unformatted text by default. As long as you saved the file with the .js extension (you named it index.js, so that’s perfect), Node.js and AWS will treat it exactly like any other JavaScript file. No hidden formatting issues to worry about here.

3. How will the cloud environment recognize the ParseServer class without importing the library?

It won’t—this is a key missing step! You need to explicitly import the Parse Server module at the top of your index.js file. Add these lines before your ParseServer initialization:

const ParseServer = require('parse-server').ParseServer;
// If you plan to use the Parse SDK in your code, add this too:
// const Parse = require('parse');

Without this import, Node.js will throw a ReferenceError: ParseServer is not defined error when trying to run your code.

4. Do you need to add more code to index.js?

Yes—you need a few more lines to make the server actually run. Parse Server relies on Express, so you’ll need to set up an Express app, mount the Parse Server instance to a route, and start the server on an open port (like 1337, which is standard for Parse).

Here’s a complete minimal index.js that includes your email adapter:

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const app = express();

const server = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev', // Replace with your MongoDB URI (or AWS DocumentDB)
  appId: 'your-unique-app-id', // Replace with your app's ID
  masterKey: 'your-secure-master-key', // Replace with your master key
  serverURL: 'http://localhost:1337/parse', // Internal server URL
  verifyUserEmails: true,
  publicServerURL: 'https://your-ec2-public-ip/parse', // Replace with your EC2 public URL + /parse route
  appName: 'Your App Name',
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      fromAddress: 'parse@your-mailgun-domain.com',
      domain: 'your-mailgun-domain.com', // Your verified Mailgun domain
      apiKey: 'your-mailgun-api-key',
    }
  }
});

// Mount Parse Server at the /parse route
app.use('/parse', server);

// Start the server
const port = 1337;
app.listen(port, () => {
  console.log(`Parse Server running on http://localhost:${port}/parse`);
});

Don’t forget to replace all placeholder values (like database URI, app ID, and public URL) with your actual AWS/Parse/Mailgun details. You’ll also need a MongoDB instance (either running on your EC2 or using AWS DocumentDB) for Parse Server to connect to.

5. What else do you need in your cloud code package?

Your deployment package must include these components for CodeDeploy to successfully set up your server:

  • index.js: The main server file we just updated.
  • package.json: This file lists all your project dependencies (like parse-server, express, and parse-server-simple-mailgun-adapter). You already ran npm init, so run these commands in your project folder to add and save the required dependencies:
    npm install parse-server express parse-server-simple-mailgun-adapter --save
    
  • appspec.yml: A CodeDeploy configuration file that tells AWS how to deploy your code. Here’s a basic example:
    version: 0.0
    os: linux
    files:
      - source: /
        destination: /home/ec2-user/parse-server
    hooks:
      BeforeInstall:
        - location: scripts/install_dependencies.sh
          timeout: 300
          runas: ec2-user
      ApplicationStart:
        - location: scripts/start_server.sh
          timeout: 300
          runas: ec2-user
    
  • Deployment scripts: Create a scripts folder with two files:
    • install_dependencies.sh: Runs npm install in the EC2 destination folder:
      cd /home/ec2-user/parse-server
      npm install
      
    • start_server.sh: Starts the server (use PM2 to keep it running in the background—install PM2 first on EC2 with npm install -g pm2):
      cd /home/ec2-user/parse-server
      pm2 start index.js --name parse-server
      
  • Optional: A cloud folder if you have Parse cloud functions to deploy.

Bonus: Choosing a sender domain for Mailgun

Mailgun requires a verified domain to send emails—you have three options:

  • Your existing domain: Use a domain you already own (e.g., yourdomain.com). You’ll need to add DNS records (TXT, MX, CNAME) provided by Mailgun to your domain’s DNS settings (via your registrar or AWS Route 53).
  • A subdomain: Use a subdomain of your existing domain (e.g., mail.yourdomain.com). This is often easier since you won’t modify your main domain’s core DNS records.
  • Mailgun sandbox domain: For testing, use Mailgun’s free sandbox domain (e.g., sandboxxxxx.mailgun.org). You can only send test emails to verified recipients with this, but it’s great for initial setup testing.

Quick AWS Deployment Checklist

  1. Ensure your EC2 instance has the CodeDeploy agent installed and running.
  2. Update your EC2 security group to allow inbound traffic on port 1337 (or whatever port you’re using for Parse Server) and outbound traffic for npm installs/Mailgun API calls.
  3. Zip up your entire project folder (including index.js, package.json, appspec.yml, and scripts folder) and upload it to your S3 bucket.
  4. Create a CodeDeploy deployment to push the package from S3 to your EC2 instance.
  5. Check CodeDeploy logs if you run into issues—they’ll help you debug deployment errors quickly.

内容的提问来源于stack exchange,提问作者Adam J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:03:45