create database in Athena

Today , I will discuss about “How to create Database in Athena.Follow the below steps to achieve the same.
* Create IAM policy which gives access to S3 bucket for Athena Logs to the required user.
* While creating that IAM policy, you need to put the below content in the JSON tab.
* Here, in below JSON, you need to change the bucket Name.
* If you see clearly , in JSON both Glue and Athena has mentioned , so if you don’t want to give access to Glue DB, then you can remove that section and Keep only Athena Section only.

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“s3:GetObject”,
“s3:PutObject”,
“s3:AbortMultipartUpload”,
“s3:ListMultipartUploadParts”,
“s3:DeleteObject”
],
“Resource”: [
“arn:aws:s3:::yourbucketname/*
]
},
{ “Effect”: “Allow”,
“Action”: [
“s3:GetBucketLocation”,
“s3:CreateBucket”,
“s3:ListBucket”,
“s3:ListBucketMultipartUploads”,
“s3:DeleteObject”
],
“Resource”: [
“arn:aws:s3:::yourbucketname
]
},
{
“Effect”: “Allow”,
“Action”: [
“athena:*”
],
“Resource”: [
“*” ]
},
{
“Effect”: “Allow”,
“Action”: [
“glue:CreateDatabase”,
“glue:DeleteDatabase”,
“glue:GetDatabase”,
“glue:GetDatabases”,
“glue:UpdateDatabase”,
“glue:CreateTable”,
“glue:DeleteTable”,
“glue:BatchDeleteTable”,
“glue:UpdateTable”,
“glue:GetTable”,
“glue:GetTables”,
“glue:BatchCreatePartition”,
“glue:CreatePartition”,
“glue:DeletePartition”,
“glue:BatchDeletePartition”,
“glue:UpdatePartition”,
“glue:GetPartition”,
“glue:GetPartitions”,
“glue:BatchGetPartition”
],
“Resource”: [
“*”
]
}
]
}

* Once Policy is created. Go to Athena and set up query result location which will be S3 bucket location.


* Give path as s3://yourBucketName/log-Folder and Click on Save. Set Encryption settings if required.

* To create database in Athena workspace, run the below command
create Database Db_Athena. See the below SS for the same.Click on “Run Query”. Database get created.

Related posts