Serverless backend for ingesting and exposing SpaceX launch data.
Built with AWS Lambda, DynamoDB, API Gateway, and automated using SAM and GitHub Actions.
SpacexBackend/ # Backend (Lambda functions + API Gateway + DynamoDB)
.
├── api-docs/
│ ├── swagger_template.yaml # Template file (with placeholder for API URL)
│ ├── swagger_ui/
│ │ └── index.html # Swagger UI HTML
│ └── upload_swagger.sh # Upload script (replaces API URL + syncs to S3)
├── aws_lambda/
│ ├── fetch_launches/ # Lambda to fetch SpaceX launches and store in DynamoDB
│ └── get_launches/ # Lambda to expose latest launches via GET
├── tests/ # Unit tests per lambda
├── .github/workflows/ # GitHub Actions CI/CD workflows
│ ├── deploy-backend.yml
│ └── test-backend.yml
├── template.yaml # SAM infrastructure template
├── samconfig.toml # SAM deployment config
├── requirements.txt # Shared dependencies (if needed)
└── README.mdThis project includes an OpenAPI specification for the SpaceX Launches API.
The Swagger UI is automatically deployed to S3 every time swagger_template.yaml or upload_swagger.sh is modified on the main branch.
Once deployed, Swagger UI will be available at: swagger
- AWS CLI configured (with credentials)
- AWS SAM CLI installed
- Python 3.10+
sam build
sam deploy --guidedYou’ll be prompted to set:
- Stack name: spacex-backend
- Region: e.g., us-east-1
- IAM capabilities: CAPABILITY_IAM
- Save configuration: yes → will create samconfig.toml
sam deployThis project uses AWS SAM to provision the full backend infrastructure automatically.
- AWS CLI configured (
aws configure) - AWS SAM CLI installed (
sam --version) - Python 3.10 or higher
- Clone the repository:
git clone https://github.com/your-username/SpacexBackend.git
cd SpacexBackend- Build the SAM application:
sam build- Deploy the stack for the first time:
sam deploy --guidedYou’ll be prompted to configure: Stack name →
spacex-backendAWS region →us-east-1Capabilities →CAPABILITY_IAMSave config to samconfig.toml →Yes
- On future deployments:
sam deployThe Swagger UI is hosted on an S3 bucket configured as a static website.
Make sure your folder api-docs/swagger_ui/ contains:
index.html→ Swagger UI frontendswagger.yaml→ Generated API definition (automatically injected from template)
- Make the upload script executable:
chmod +x api-docs/upload_swagger.sh- Run the script:
bash ./api-docs/upload_swagger.shThis will:
- Inject the deployed API Gateway URL into your swagger_template.yaml.
- Generate swagger_ui/swagger.yaml.
- Upload the entire swagger_ui/ folder to the S3 bucket created by SAM.
⚠️ The bucket name is automatically derived as:spacex-swagger-ui-<your-account-id>
Tests are isolated per lambda.
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pytest --cov=aws_lambda tests/- On push to main
- On pull request to main
- Installs dependencies
- Runs all unit tests
- Shows coverage report
- Runs tests
- Builds SAM application
- Deploys stack to AWS
- Exports API Gateway URL (SpaceXLaunchesApiEndpoint)
- Watches for changes to
swagger_template.yamlorupload_swagger.sh. - Automatically rebuilds Swagger and syncs it to the S3 bucket.
- Uses outputs from the backend stack to inject the correct API URL.
AWS credentials and region are managed via GitHub Secrets and Environment Variables.
graph TD
SpaceXAPI[SpaceX API] -->|fetch_launches.py| FetchLambda
FetchLambda -->|PutItem| DynamoDBTable(SpaceXLaunchesDB)
User -->|GET /launches| ApiGateway
ApiGateway --> GetLambda
GetLambda -->|Scan| DynamoDBTable
- fetch_launches Lambda runs every 6 hours (cron schedule).
- get_launches Lambda exposes the last 10 launches via HTTP GET.
- All infrastructure is deployed via template.yaml.
The backend exposes this output:
Outputs:
SpaceXLaunchesApiEndpoint:
Description: "Base URL for the SpaceX Launches HTTP API"
Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com"
Export:
Name: SpaceXLaunchesApiEndpointThis URL is consumed by the frontend through CI and injected into the build.
This solution is scalable and professional:
- Add new Lambdas in aws_lambda/
- Add integration tests with mocks or live resources
- Add rollback handling in CI with sam deploy versions
- Integrate monitoring via CloudWatch
✅ Infrastructure as Code (SAM)
✅ Automated testing and deployment (CI/CD)
✅ Separation of logic per lambda
✅ Cloud-native, production-ready stack