API documentation
Swagger is a tool that helps to document APIs
Objective:
Have my API documentation hosted.
Choose to do Static website hosting behind CloudFront
Note: One can avoid CloudFront, by directly hosting in S3. But there is a problem, S3 bucket doesn’t support https... issue related to SSL. Hence using CloudFront for now.
How did I do?
- CLI
docker run -p ${PORT}:8080 \
-e SWAGGER_JSON=/notes/${GIVE_CONFIG_FILENAME} \
-v ${DIR}:/notes \
-d swaggerapi/swagger-ui
docker exec -it <container-id> /bin/sh
cd /usr/share/nginx/html/
cp * /notes
I got all the files that can simply be hosted
- Create S3 bucket docs.xyzapi.ashwiniag.com
- Block all public access
- Set static webhosting option and chose default file index.html
- set bucket policy
{
"Version": "2008-10-17",
"Id": "PolicyForPublicWebsiteContent",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket name>/*"
}
]
}
- Copy files to bucket
aws s3 cp . s3://<bucket_name> --recursive --exclude "some.json"
- Create cloudfront (self explanatory )
Note:
- point to bucket created
- Choose Https and SSL certificate
# TIL:
TO use a certificate in CloudFront, we need to create the certificate in us-east. Because CDN maintained in us-east region. Hence, we should have a valid certification from there.
Created certificate *.ashwiniag.com
And its DONE!
TO Delete cache
Click on respective CloudFront --> Invalidation tab --> create invalidation --> entry for object path: /*.