A simple CMS (Content Management System) that stores files by their IDs with version control.
-
Install the Serverless CLI via NPM:
npm install -g serverless
-
Create an IAM user in your AWS account with an access key and the policy "AdministratorAccess". After creating the IAM user, create the following files with the access key:
-
~/.aws/credentials
[basic-cms-aws-user] aws_access_key_id=YOUR_AWS_ACCESS_KEY_ID aws_secret_access_key=YOUR_AWS_SECRET_ACCESS_KEY
-
~/.aws/config
[profile basic-cms-aws-user] region=eu-central-1
-
-
You must create two buckets on AWS S3. Bucket names must be globally unique and must not contain spaces or uppercase letters. See rules for bucket naming.
-
Deployment Bucket (e.g. basic-cms-deployment-bucket-9f256880fd3b): This bucket is OPTIONAL and you can easily delegate bucket creation to Serverless by removing the deploymentBucket attribute from the serverless.yml file.
- All options that block public access must be disabled (e.g. Block all public access = Off).
-
Content Bucket (e.g. basic-cms-content-bucket-212486bed188):
-
All options that block public access must be disabled (e.g. Block all public access = Off).
-
The bucket versioning option should be enabled.
-
Bucket Policy (This bucket and every object in it must be publicly accessible):
{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicRead", "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject", "s3:GetObjectVersion" ], "Resource": "arn:aws:s3:::basic-cms-content-bucket-212486bed188/*" } ] }
-
Do not forget to update the bucket settings in serverless.yml as well:
provider: ... deploymentBucket: <DEPLOYMENT_BUCKET_NAME_GOES_HERE> ... environment: ... ["CMS_STORAGE_BUCKET_NAME"]: <CONTENT_BUCKET_NAME_GOES_HERE> ["CMS_STORAGE_BUCKET_URL"]: <CONTENT_BUCKET_URL_GOES_HERE> ... ...
-
Deploy the app to AWS via the Serverless framework:
sls deploy --aws-profile basic-cms-aws-user
Invoke the lambda functions locally:
sls invoke local --aws-profile basic-cms-aws-user -f upload -p events/upload_image.json
sls invoke local --aws-profile basic-cms-aws-user -f find -p events/find_images.json