### Setup S3 Bucket for Static Website Hosting - Create Bucket Source: https://github.com/mcohen01/amazonica/blob/master/README.md Part of setting up static website hosting, this snippet shows how to create the S3 bucket. ```Clojure (create-bucket bucket-name) ``` -------------------------------- ### List CodeDeploy Applications (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md A straightforward example demonstrating how to retrieve a list of all applications managed by AWS CodeDeploy within your account. ```clj (ns com.example (:use [amazonica.aws.codedeploy])) (list-applications) ``` -------------------------------- ### Setup S3 Bucket for Static Website Hosting - Upload Index Source: https://github.com/mcohen01/amazonica/blob/master/README.md Part of setting up static website hosting, this snippet shows how to upload the index.html file to the S3 bucket. ```Clojure (put-object bucket-name "index.html" (java.io.File. "index.html")) ``` -------------------------------- ### Manage AWS OpsWorks Stacks, Layers, and Instances (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Clojure examples for provisioning and managing AWS OpsWorks resources using Amazonica. This includes creating stacks, layers, and instances, as well as describing existing stacks, layers, and instances, and starting stacks or individual instances. ```clj (ns com.example (:use [amazonica.aws.opsworks])) (create-stack :name "my-stack" :region "us-east-1" :default-os "Ubuntu 12.04 LTS" :service-role-arn "arn:aws:iam::676820690883:role/aws-opsworks-service-role") (create-layer :name "webapp-layer" :stack-id "dafa328e-c529-41af-89d3-12840a31abad" :enable-auto-healing true :auto-assign-elastic-ips true :volume-configurations [ {:mount-point "/data" :number-of-disks 1 :size 50}]) (create-instance :hostname "node-app-1" :instance-type "m1.large" :stack-id "dafa328e-c529-41af-89d3-12840a31abad" :layer-ids ["660d00da-c533-43d4-8c7f-2df240fd563f"] :availability-zone "us-east-1a" :autoscaling-type "LoadBasedAutoScaling" :os "Ubuntu 12.04 LTS" :ssh-key-name "admin") (describe-stacks :stack-ids ["dafa328e-c529-41af-89d3-12840a31abad"]) (describe-layers :stack-id "dafa328e-c529-41af-89d3-12840a31abad") (describe-instances :stack-id "dafa328e-c529-41af-89d3-12840a31abad" :layer-id "660d00da-c533-43d4-8c7f-2df240fd563f" :instance-id "93bc5049-1bd4-49c8-a6ef-e84145807f71") (start-stack :stack-id "660d00da-c533-43d4-8c7f-2df240fd563f") (start-instance :instance-id "93bc5049-1bd4-49c8-a6ef-e84145807f71") ``` -------------------------------- ### Setup S3 Bucket for Static Website Hosting - Configure Website Source: https://github.com/mcohen01/amazonica/blob/master/README.md Part of setting up static website hosting, this snippet shows how to configure the S3 bucket for website hosting, specifying the index document. ```Clojure (set-bucket-website-configuration :bucket-name bucket-name :configuration { :index-document-suffix "index.html"}) ``` -------------------------------- ### Interact with AWS Step Functions in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides Clojure examples for starting AWS Step Functions state machine executions and handling activity tasks. It demonstrates how to initiate an execution and how a worker can poll for pending tasks, process input, and report success or failure back to the state machine. ```Clojure (ns com.example (:use [amazonica.aws.stepfunctions])) ;this is to start the execution, then you need to run get-activity-task-result ultimately to monitor for pending requests from the state machine components ;to execute a worker task. (start-state-machine "{\"test\":\"test\"}" "arn:aws:states:us-east-1:xxxxxxxxxx:stateMachine:test-sf") ;this will block until it returns a task in the queue from a state machine execution, ;so you need to run it in a while loop on the worker side of your app. (let [tr (get-activity-task-result "arn:aws:states:us-east-1:xxxxxxxxx:activity:test-sf-activity") input (:input tr) token (:task-token tr)] (if () (mark-task-success "" token) (mark-task-failure token)) ) ``` -------------------------------- ### Example AWS Credentials File Format Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows the standard INI-like format for the `~/.aws/credentials` file, which is required by the official AWS tools and some Amazonica tests to authenticate with AWS services using access keys. ```INI [default] aws_access_key_id = AKIAABCDEFGHIEJK aws_secret_access_key = 6rqzvpAbcd1234++zyx987WUV654sRq ``` -------------------------------- ### Manage AWS CloudFormation Stacks Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides examples for creating a CloudFormation stack from a template URL and describing resources within an existing stack using the Amazonica library. ```clj (ns com.example (:use [amazonica.aws.cloudformation])) (create-stack :stack-name "my-stack" :template-url "abcd1234.s3.amazonaws.com") (describe-stack-resources :stack-name "my_cloud_stack") ``` -------------------------------- ### Get CloudWatch Metric Data (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Example of retrieving metric data from CloudWatch within a specified time range. It demonstrates querying metrics with specific IDs and metric statistics, including namespace, metric name, dimensions, period, stat, and unit. ```clj (get-metric-data :start-time "2018-06-14T00:00:00Z" :end-time "2018-06-15T00:00:00Z" :metric-data-queries [{:id "test" :metricStat {:metric {:namespace "AWS/DynamoDB" :metricName "ProvisionedReadCapacityUnits" :dimensions [{:name "TableName" :value "MyTableName"}]} :period 86400 :stat "Sum" :unit "Count"}}]) ``` -------------------------------- ### List Cognito User Pools (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to retrieve a list of Amazon Cognito User Pools. The example shows how to limit the number of results returned using the `max-results` parameter and includes a sample output. ```clj (ns com.example (:require [amazonica.aws.cognitoidp :refer :all])) (list-user-pools {:max-results 2}) => {:user-pools [{:lambda-config {}, :last-modified-date "2017-06-16T14:16:28.950-03:00"], :creation-date "2017-06-15T16:23:04.555-03:00"], :name "Amazonica", :id "us-west-1_example"}]} ``` -------------------------------- ### Setup S3 Bucket for Static Website Hosting - Set Public Read Policy Source: https://github.com/mcohen01/amazonica/blob/master/README.md Part of setting up static website hosting, this snippet demonstrates how to set a bucket policy to allow public read access to objects. ```Clojure (let [policy {:Version "2012-10-17" :Statement [{ :Sid "PublicReadGetObject" :Effect "Allow" :Principal "*" :Action ["s3:GetObject"] :Resource [(str "arn:aws:s3:::" bucket-name "/*")]}]} json (cheshire.core/generate-string policy true)] (set-bucket-policy bucket-name json)) ``` -------------------------------- ### Manage AWS IoT Things in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to interact with AWS IoT Core to manage device 'things'. This example demonstrates listing existing IoT things and creating a new one using the Amazonica library in Clojure. ```clj (ns com.example (:require [amazonica.aws.iot :refer :all])) (list-things {}) ;; => {:things [{:thing-name "YourThing"}]} (create-thing :thing-name "MyThing") ;; => {:thing-name "MyThing" :thing-arn "arn:aws:iot:...thing/MyThing"} ``` -------------------------------- ### Describe AWS CloudWatch Log Streams (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md A Clojure example demonstrating how to describe AWS CloudWatch Log Streams using Amazonica. The example shows how to filter by a specific log group name and order the results by the last event time in descending order. ```clj (ns com.example (:use [amazonica.aws.logs])) (describe-log-streams :log-group-name "my-log-group" :order-by "LastEventTime" :descending true) ``` -------------------------------- ### Configure AWS Client with Proxy Settings (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to include a `:client-config` entry within the credentials map to customize the underlying `ClientConfiguration`. This example demonstrates setting proxy host and port for the AWS client. ```clj (describe-images {:client-config {:proxy-host "proxy.address.com" :proxy-port 8080}}) ``` -------------------------------- ### Get S3 Bucket Tagging Configuration Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates how to retrieve the tagging configuration associated with an S3 bucket. ```Clojure (get-bucket-tagging-configuration {:bucket-name bucket}) ``` -------------------------------- ### ECR Repository Operations (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides examples for interacting with Amazon Elastic Container Registry (ECR), covering repository creation, description, image listing, and authorization token retrieval. ```clj (require '[amazonica.aws.ecr :as ecr]) (ecr/describe-repositories {}) (ecr/create-repository :repository-name "amazonica") (ecr/get-authorization-token {}) (ecr/list-images :repository-name "amazonica") (ecr/delete-repository :repository-name "amazonica") ``` -------------------------------- ### Manage AWS Pinpoint Resources with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to interact with AWS Pinpoint using Amazonica, including retrieving application IDs, creating segments, launching campaigns, and sending messages. It shows the setup for an application, segment, campaign, and message sending. ```Clojure (ns com.example (:require [amazonica.aws.pinpoint :as pp])) (defn app-id [] (-> (pp/get-apps {}) :applications-response :item first :id)) (pp/create-segment {:application-id (app-id)}) (pp/create-campaign {:application-id (app-id) :write-campaign-request {:segment-id "a668b484bec94cb1252772032ecdf540" :name "my-campaign" :schedule {:frequency "ONCE" :start-time "2017-09-27T20:36:11+00:00"} :message-configuration {:default-message {:body "hello world"}}}}) (pp/send-messages {:application-id (app-id) :message-request {:addresses {"+18132401139" {:channel-type "SMS"}} :message-configuration {:default-message {:body "hello world"}}}}) ``` -------------------------------- ### Create CloudWatchEvents Rule and Targets (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates how to create a CloudWatch Event Rule with a cron schedule and then associate targets to that rule. The example shows linking a Lambda function as a target and passing JSON input arguments. ```clj (ns com.example (:use [amazonica.aws.cloudwatchevents])) (put-rule :name "nightly-backup" :description "Backup DB nightly at 10:00 UTC (2 AM or 3 AM Pacific)" :schedule-expression "cron(0 10 * * ? *)") (put-targets :rule "nightly-backup" :targets [{:id "backup-lambda" :arn "arn:aws:lambda:us-east-1:123456789012:function:backup-lambda" :input (json/write-str {"whatever" "arguments"})}]) ``` -------------------------------- ### Clojure DynamoDBV2 Setup and Table Creation with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This snippet demonstrates how to set up the Amazonica DynamoDBV2 namespace and define AWS credentials. It then proceeds to create a new DynamoDB table named 'TestTable' with a complex schema, including primary keys, attribute definitions, local secondary indexes, and provisioned throughput settings. ```clj (ns com.example (:use [amazonica.aws.dynamodbv2])) (def cred {:access-key "aws-access-key" :secret-key "aws-secret-key" :endpoint "http://localhost:8000"}) (create-table cred :table-name "TestTable" :key-schema [{:attribute-name "id" :key-type "HASH"} {:attribute-name "date" :key-type "RANGE"}] :attribute-definitions [{:attribute-name "id" :attribute-type "S"} {:attribute-name "date" :attribute-type "N"} {:attribute-name "column1" :attribute-type "S"} {:attribute-name "column2" :attribute-type "S"}] :local-secondary-indexes [{:index-name "column1_idx" :key-schema [{:attribute-name "id" :key-type "HASH"} {:attribute-name "column1" :key-type "RANGE"}] :projection {:projection-type "INCLUDE" :non-key-attributes ["id" "date" "column1"]}} {:index-name "column2_idx" :key-schema [{:attribute-name "id" :key-type "HASH"} {:attribute-name "column2" :key-type "RANGE"}] :projection {:projection-type "ALL"}}] :provisioned-throughput {:read-capacity-units 1 :write-capacity-units 1}) ``` -------------------------------- ### Put CloudWatch Metric Alarm (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create or update a CloudWatch metric alarm. This example sets an alarm named 'my-alarm' with specific evaluation periods, metric name ('CPU'), and a threshold of '50%'. ```clj (ns com.example (:use [amazonica.aws.cloudwatch])) (put-metric-alarm :alarm-name "my-alarm" :actions-enabled true :evaluation-periods 5 :period 60 :metric-name "CPU" :threshold "50%") ``` -------------------------------- ### Manage Amazonica Dependencies for Reduced Uberjar Size Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides a Leiningen dependency configuration example demonstrating how to exclude the full AWS Java SDK and selectively include only the necessary service-specific SDKs (e.g., S3) to significantly reduce the final uberjar size, which is beneficial for memory-constrained environments. ```Clojure :dependencies [[org.clojure/clojure "1.10.3"] [amazonica "0.3.156" :exclusions [com.amazonaws/aws-java-sdk com.amazonaws/amazon-kinesis-client com.amazonaws/dynamodb-streams-kinesis-adapter]] [com.amazonaws/aws-java-sdk-core "1.11.968"] [com.amazonaws/aws-java-sdk-s3 "1.11.968"]] ``` -------------------------------- ### Retrieve AWS IoT Thing Shadow in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to retrieve the device shadow, which represents the current state of an AWS IoT thing. This example uses the `amazonica.aws.iotdata` namespace to fetch the shadow for a specified thing name in Clojure. ```clj (ns com.example (:require [amazonica.aws.iotdata :refer :all])) (get-thing-shadow :thing-name "MyThing") ``` -------------------------------- ### Manage AWS Route53 Domains with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to interact with AWS Route53 Domains for domain management. Examples include listing domains, checking domain availability and transferability, retrieving domain details, and registering a new domain with contact information. ```Clojure (ns com.example (:use [amazonica.aws.route53domains])) (list-domains) (check-domain-availability :domain-name "amazon.com") (check-domain-transferability :domain-name "amazon.com") (get-domain-detail :domain-name "amazon.com") (let [contact {:first-name "Michael" :last-name "Cohen" :organization-name "amazonica" :address-line1 "375 11th St" :city "San Francisco" :state "CA" :zip-code "94103-2097" :country-code "US" :email "" :phone-number "+1.4158675309" :contact-type "PERSON"}] (register-domain :domain-name "amazon.com" :duration-in-years 10 :auto-renew true :tech-contact contact :admin-contact contact :registrant-contact contact)) ``` -------------------------------- ### Manage DataPipeline Operations (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides examples for common AWS Data Pipeline operations. This includes creating a new pipeline, defining its structure with pipeline objects and fields, listing existing pipelines, and deleting a pipeline by its ID. ```clj (ns com.example (:use [amazonica.aws.datapipeline])) (create-pipeline :name "my-pipeline" :unique-id "mp") (put-pipeline-definition :pipeline-id "df-07746012XJFK4DK1D4QW" :pipeline-objects [{:name "my-pipeline-object" :id "my-pl-object-id" :fields [{:key "some-key" :string-value "foobar"}]}]) (list-pipelines) (delete-pipeline :pipeline-id pid) ``` -------------------------------- ### Clojure Kinesis Analytics Application Creation Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create a Kinesis Analytics application using Amazonica. The example shows configuring the application name, defining input sources (e.g., Kinesis stream with JSON record format), and specifying outputs. ```clj (ns com.example (:require [amazonica.aws.kinesisanalytics :as ka])) (ka/create-application :application-name "my-ka-app" :inputs [ {:name-prefix "prefix_" :input-schema {:record-format {:record-format-type "json"}} :kinesis-treams-input {:resource-ARN "fobar"}} ] :outputs [...]) ``` -------------------------------- ### Set S3 Bucket Notification Configuration Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to configure S3 bucket notifications, for example, to send events like object creation to an SQS queue, with optional filtering. ```Clojure (s3/set-bucket-notification-configuration :bucket-name "my.bucket.name" :notification-configuration {:configurations {:some-config-name {:queue "arn:aws:sqs:eu-west-1:123456789012:my-sqs-queue-name" :events #{"s3:ObjectCreated:*"} :filter [{"foo" "bar"} {:baz "quux"} ["key" "value"]]}}}) ``` -------------------------------- ### Clojure DynamoDBV2 Scan Table with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This example demonstrates performing a full scan operation on the 'TestTable' DynamoDB table. A scan reads every item in the table and is generally less efficient than a query for filtered results. ```clj (scan cred :table-name "TestTable") ``` -------------------------------- ### Put CloudWatch Metric Data (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to publish custom metric data to CloudWatch. The example specifies an endpoint, namespace, metric name, unit, value, and dimensions for the metric. It defaults to 'us-east-1' if no endpoint is provided. ```clj (put-metric-data {:endpoint "us-west-1"} ;; Defaults to us-east-1 :namespace "test_namespace" :metric-data [{:metric-name "test_metric" :unit "Count" :value 1.0 :dimensions [{:name "test_name" :value "test_value"}]}]) ``` -------------------------------- ### Manage AWS Forecast Resources with Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates a full workflow for AWS Forecast, including creating datasets, dataset groups, importing data from S3, creating predictors, generating forecasts, querying forecasts, and cleaning up resources using Amazonica in Clojure. This comprehensive example covers the typical lifecycle of a machine learning forecast model. ```clj (require '[amazonica.aws.forecast :as fc]) (fc/create-dataset :dataset-name "hourly_ts" :data-frequency "H" :dataset-type "TARGET_TIME_SERIES" :domain "CUSTOM" :schema { :attributes [ { :attribute-name "timestamp" :attribute-type "timestamp" }, { :attribute-name "target_value" :attribute-type "float" }, { :attribute-name "item_id" :attribute-type "string" }]}) ;; {:dataset-arn "arn:aws:forecast:us-east-1:123456789012:dataset/hourly_ts"} (fc/create-dataset-group :dataset-arns ["arn:aws:forecast:us-east-1:123456789012:dataset/hourly_ts"] :dataset-group-name "hourly_ts" :domain "CUSTOM") ;; {:dataset-group-arn "arn:aws:forecast:us-east-1:123456789012:dataset-group/hourly_ts"} (require '[amazonica.aws.s3 :as s3]) (s3/put-object "amazonica-forecast" "hourly_ts.csv" (java.io.File. "/path/to/hourly_ts.csv")) (fc/create-dataset-import-job :dataset-import-job-name "import_hourly_ts_job" :dataset-arn "arn:aws:forecast:us-east-1:123456789012:dataset/hourly_ts" :data-source { :s3-config { :path "s3://amazonica-forecast/hourly_ts.csv" :role-arn "arn:aws:iam::123456789012:role/amazonica"}}) ;; {:dataset-import-job-arn "arn:aws:forecast:us-east-1:123456789012:dataset-import-job/hourly_ts/import_hourly_ts_job"} (fc/create-predictor :input-data-config { :dataset-group-arn "arn:aws:forecast:us-east-1:123456789012:dataset-group/hourly_ts"} :algorithm-arn "arn:aws:forecast:::algorithm/ARIMA" :forecast-horizon 336 :featurization-config { :forecast-frequency "H"} :predictor-name "hourly_ts_predictor") (fc/create-forecast :forecast-name "hourly_ts" :predictor-arn "arn:aws:forecast:us-east-1:123456789012:predictor/hourly_ts_predictor") (require '[amazonica.aws.forecastquery :as fq]) (fq/query-forecast :forecast-arn "arn:aws:forecast:us-east-1:123456789012:forecast/hourly_ts" :filters {"item_id" "item1"}) (fc/delete-forecast :forecast-arn "arn:aws:forecast:us-east-1:123456789012:forecast/hourly_ts") (fc/delete-predictor :predictor-arn "arn:aws:forecast:us-east-1:123456789012:predictor/hourly_ts_predictor") (fc/delete-dataset :dataset-arn "arn:aws:forecast:us-east-1:123456789012:dataset/hourly_ts") (fc/delete-dataset-group :dataset-group-arn "arn:aws:forecast:us-east-1:123456789012:dataset-group/hourly_ts") ``` -------------------------------- ### Manage AWS IAM Users and Policies in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates how to programmatically manage AWS Identity and Access Management (IAM) resources. This example shows how to create an IAM user, generate an access key for that user, and attach an inline S3 access policy using Amazonica in Clojure. ```clj (ns com.example (:use [amazonica.aws.identitymanagement])) (def policy "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Action\": [\"s3:*\"], \"Effect\": \"Allow\", \"Resource\": [\"arn:aws:s3:::bucket-name/*\"]}]}") (create-user :user-name "amazonica") (create-access-key :user-name "amazonica") (put-user-policy :user-name "amazonica" :policy-name "s3policy" :policy-document policy) ``` -------------------------------- ### Manage AWS KMS Keys (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Clojure examples for interacting with AWS Key Management Service (KMS) using Amazonica. This includes operations for creating new keys, listing existing keys, and disabling a specific key by its ID. ```clj (ns com.example (:use [amazonica.aws.kms])) (create-key) (list-keys) (disable-key "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") ``` -------------------------------- ### Clojure DynamoDBV2 Query Table with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This example demonstrates how to query the 'TestTable' using a local secondary index ('column1_idx'). It specifies key conditions, a limit, select attributes, and scan direction to retrieve filtered items efficiently. ```clj (query cred :table-name "TestTable" :limit 1 :index-name "column1_idx" :select "ALL_ATTRIBUTES" :scan-index-forward true :key-conditions {:id {:attribute-value-list ["foo"] :comparison-operator "EQ"} :column1 {:attribute-value-list ["first na"] :comparison-operator "BEGINS_WITH"}}) ``` -------------------------------- ### Manage AWS Lambda Functions (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Clojure examples for interacting with AWS Lambda functions using Amazonica. This includes creating a new Lambda function with an inline Node.js handler and invoking an existing Lambda function with a JSON payload. ```clj (ns com.example (:use [amazonica.aws.lambda])) (let [role "arn:aws:iam::123456789012:role/some-lambda-role" handler "exports.helloWorld = function(event, context) {\n console.log('value1 = ' + event.key1)\n console.log('value2 = ' + event.key2)\n console.log('value3 = ' + event.key3)\n context.done(null, 'Hello World')\n }"] (create-function :role role :function handler)) (invoke :function-name "helloWorld" :payload "{\"key1\": 1, \"key2\": 2, \"key3\": 3}") ``` -------------------------------- ### Example Output of Describe Availability Zones Call in Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This Clojure map represents the typical output structure returned by the `describe-availability-zones` function in Amazonica. It shows a list of availability zones, each with its state, region name, zone name, and messages, after the AWS Java result has been marshalled into Clojure data. ```Clojure {:availability-zones [{:state "available", :region-name "us-east-1", :zone-name "us-east-1a", :messages []} {:state "available", :region-name "us-east-1", :zone-name "us-east-1b", :messages []} {:state "available", :region-name "us-east-1", :zone-name "us-east-1c", :messages []} {:state "available", :region-name "us-east-1", :zone-name "us-east-1d", :messages []} {:state "available", :region-name "us-east-1", :zone-name "us-east-1e", :messages []}]} ``` -------------------------------- ### Detect Comprehend Entities (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Example of using Amazon Comprehend to detect entities (such as persons and locations) within a given text string. It specifies the language code for analysis and shows the structured output with entity details. ```clj (ns com.example (:require [amazonica.aws.comprehend :refer :all])) (amazonica.aws.comprehend/detect-entities {:language-code "en" :text "Hi my name is Joe Bloggs and I live in Glasgow, Scotland"}) => {:entities [{:type "PERSON", :text "Joe Bloggs", :score 0.99758613, :begin-offset 14, :end-offset 24} {:type "LOCATION", :text "Glasgow, Scotland", :score 0.93267196, :begin-offset 39, :end-offset 56}]} ``` -------------------------------- ### Configure Maven Repository and Dependency for Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md Instructions to add the Clojars repository and Amazonica dependency to a Maven project's pom.xml. This setup allows Maven to resolve and include the Amazonica library in your Java or Clojure project. ```xml clojars.org http://clojars.org/repo ``` ```xml amazonica amazonica 0.3.168 ``` -------------------------------- ### List AWS EMR Resources with Amazonica Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides examples for listing various AWS Elastic MapReduce (EMR) resources, including active clusters, describing a specific cluster by ID, listing steps within a cluster, and listing bootstrap actions associated with a cluster. This helps in monitoring and managing EMR environments. ```clj (list-clusters) (describe-cluster :cluster-id "j-38BW9W0NN8YGV") (list-steps :cluster-id "j-38BW9W0NN8YGV") (list-bootstrap-actions :cluster-id "j-38BW9W0NN8YGV") ``` -------------------------------- ### Clojure DynamoDBV2 Batch Get Items with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This snippet illustrates how to retrieve multiple items from 'TestTable' in a single batch request. It specifies the primary keys of the items to fetch, requests consistent reads, and defines a list of attributes to retrieve for each item. ```clj (batch-get-item cred :return-consumed-capacity "TOTAL" :request-items { "TestTable" {:keys [{"id" {:s "foobar"} "date" {:n 3172671}} {"id" {:s "foo"} "date" {:n 123456}}] :consistent-read true :attributes-to-get ["id" "text" "column1"]}}) ``` -------------------------------- ### Manage AWS Simple Workflow Service (SWF) Resources in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides Clojure examples for registering and deprecating domains, activity types, and workflow types within AWS Simple Workflow Service (SWF) using Amazonica. It illustrates the full lifecycle of SWF resource management, from creation to deprecation. ```Clojure (ns com.example (:use [amazonica.aws.simpleworkflow])) (def domain "my-wkfl") (def version "1.0") (register-domain :name domain :workflow-execution-retention-period-in-days "30") (register-activity-type :domain domain :name "my-worflow" :version version) (register-workflow-type :domain domain :name "my-worflow" :version version) (deprecate-activity-type :domain domain :activity-type {:name "my-worflow" :version version}) (deprecate-workflow-type :domain domain :workflowType {:name "my-worflow" :version version}) (deprecate-domain :name domain) ``` -------------------------------- ### Interact with AWS Glacier Vaults and Archives in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides Clojure examples for managing AWS Glacier vaults and archives. This includes operations such as creating, describing, and listing vaults, as well as uploading and deleting archives and vaults using the Amazonica library. ```clj (ns com.example (:use [amazonica.aws.glacier])) (create-vault :vault-name "my-vault") (describe-vault :vault-name "my-vault") (list-vaults :limit 10) (upload-archive :vault-name "my-vault" :body "upload.txt") (delete-archive :account-id "-" :vault-name "my-vault" :archive-id "pgy30P2FTNu_d7buSVrGawDsfKczlrCG7Hy6MQg53ibeIGXNFZjElYMYFm90mHEUgEbqjwHqPLVko24HWy7DU9roCnZ1djEmT-1REvnHKHGPgkuzVlMIYk3bn3XhqxLJ2qS22EYgzg", :checksum "83a05fd1ce759e401b44fff8f34d40e17236bbdd24d771ec2ca4886b875430f9", :location "/676820690883/vaults/my-vault/archives/pgy30P2FTNu_d7buSVrGawDsfKczlrCG7Hy6MQg53ibeIGXNFZjElYMYFm90mHEUgEbqjwHqPLVko24HWy7DU9roCnZ1djEmT-1REvnHKHGPgkuzVlMIYk3bn3XhqxLJ2qS22EYgzg") (delete-vault :vault-name "my-vault") ``` -------------------------------- ### Create AWS EMR Job Flow with Amazonica Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates how to initiate a new AWS Elastic MapReduce (EMR) job flow. This example includes setting the job flow name, log URI, instance group configurations (master, spot instances with bid price), and defining a Hadoop JAR step with a main class and arguments. ```clj (run-job-flow :name "my-job-flow" :log-uri "s3n://emr-logs/logs" :instances {:instance-groups [ {:instance-type "m1.large" :instance-role "MASTER" :instance-count 1 :market "SPOT" :bid-price "0.10"}]} :steps [ {:name "my-step" :hadoop-jar-step {:jar "s3n://beee0534-ad04-4143-9894-8ddb0e4ebd31/hadoop-jobs/bigml" :main-class "bigml.core" :args ["s3n://beee0534-ad04-4143-9894-8ddb0e4ebd31/data" "output"]}}]) ``` -------------------------------- ### Manage AWS Route53 Resources with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides examples for managing various AWS Route53 resources, including creating and retrieving health checks, creating and listing hosted zones, listing resource record sets, and deleting health checks and hosted zones. ```Clojure (ns com.example (:use [amazonica.aws.route53])) (create-health-check :health-check-config {:port 80, :type "HTTP", :ipaddress "127.0.0.1", :fully-qualified-domain-name "example.com"}) (get-health-check :health-check-id "ce6a4aeb-acf1-4923-a116-cd9ae2c30ee3") (create-hosted-zone :name "example69.com" :caller-reference (str (java.util.UUID/randomUUID))) (get-hosted-zone :id "Z3TKY0VR5CH45U") (list-hosted-zones) (list-health-checks) (list-resource-record-sets :hosted-zone-id "ZN8D0HXQLVRRL") (delete-health-check :health-check-id "99999999-1234-4923-a116-cd9ae2c30ee3") (delete-hosted-zone :id "my-bogus-hosted-zone") ``` -------------------------------- ### Retrieve AWS Systems Manager Parameter in Clojure Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to retrieve a parameter by name from AWS Systems Manager Parameter Store using the Amazonica library in Clojure. This snippet shows the basic setup for requiring the SSM namespace and calling the `get-parameter` function. ```Clojure (ns com.example (:require [amazonica.aws.simplesystemsmanagement :as ssm])) (ssm/get-parameter :name "my-param-name") ``` -------------------------------- ### Clojure DynamoDBV2 Put Item with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This example shows how to insert a new item into the 'TestTable' DynamoDB table using Amazonica. It includes various data types like strings, numbers, sets, and nested maps/lists, along with options to return consumed capacity and item collection metrics. ```clj (put-item cred :table-name "TestTable" :return-consumed-capacity "TOTAL" :return-item-collection-metrics "SIZE" :item { :id "foo" :date 123456 :text "barbaz" :column1 "first name" :column2 "last name" :numberSet #{1 2 3} :stringSet #{"foo" "bar"} :mixedList [1 "foo"] :mixedMap {:name "baz" :secret 42}}) ``` -------------------------------- ### Manage AWS Kinesis Firehose Delivery Streams (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Clojure examples for interacting with AWS Kinesis Firehose delivery streams using Amazonica. This includes operations like listing, describing, creating, updating destinations, putting individual records, and putting batches of records. Records can be various types, including byte buffers and CSV strings. ```clj (ns com.example (:require [amazonica.aws.kinesisfirehose :as fh]) (:import [java.nio ByteBuffer])) ;; List delivery streams (fh/list-delivery-streams) ;; => {:delivery-stream-names ("test-firehose" "test-firehose-2"), :has-more-delivery-streams false} (fh/describe-delivery-stream :delivery-stream-name "my-test-firehose") ;; => {:delivery-stream-description ;; {:version-id "2", ....}} (fh/create-delivery-stream :delivery-stream-name "my-test-firehose-2" :s3DestinationConfiguration {:role-arn "arn:aws:iam:xxxx:role/firehose_delivery_role", :bucket-arn "arn:aws:s3:::my-test-bucket"}) ;; => {:delivery-stream-arn "arn:aws:firehose:us-west-2:xxxxx:deliverystream/my-test-firehose-2"} ;; Describe delivery stream (fh/describe-delivery-stream cred :delivery-stream-name stream-name) ;; Update destination (fh/update-destination cred {:current-delivery-stream-version-id version-id :delivery-stream-name stream-name :destination-id destination-id :s3-destination-update {:BucketARN (str "arn:aws:s3:::" new-bucket-name) :BufferingHints {:IntervalInSeconds 300 :SizeInMBs 5} :CompressionFormat "UNCOMPRESSED" :EncryptionConfiguration {:NoEncryptionConfig "NoEncryption"} :Prefix "string" :RoleARN "arn:aws:iam::123456789012:role/firehose_delivery_role"}}) ;; Put batch of records to stream. Records are converted to instances of ByteBuffer if possible. Sequences are converted to CSV formatted strings for injestion into RedShift. (fh/put-record-batch cred stream-name [[1 2 3 4]["test" 2 3 4] "\"test\",2,3,4" (ByteBuffer. (.getBytes "test,2,3,4"))]) ;; Put individual record to stream. (fh/put-record stream-name "test") ;; Delete delivery stream (fh/delete-delivery-stream "stream-name") ``` -------------------------------- ### Create and Manage AWS Autoscaling Resources Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create a launch configuration and an auto-scaling group, and then list auto-scaling instances using the Amazonica library for AWS Autoscaling. ```clj (ns com.example (:use [amazonica.aws.autoscaling])) (create-launch-configuration :launch-configuration-name "aws_launch_cfg" :block-device-mappings [ {:device-name "/dev/sda1" :virtual-name "vol-b0e519c3" :ebs {:snapshot-id "snap-36295e51" :volume-size 32}}] :ebs-optimized true :image-id "ami-6fde0d06" :instance-type "m1.large" :spot-price ".10") (create-auto-scaling-group :auto-scaling-group-name "aws_autoscale_grp" :availability-zones ["us-east-1a" "us-east-1b"] :desired-capacity 3 :health-check-grace-period 300 :health-check-type "EC2" :launch-configuration-name "aws_launch_cfg" :min-size 3 :max-size 3) (describe-auto-scaling-instances) ``` -------------------------------- ### Create S3 Bucket Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create a new S3 bucket using the Amazonica library. ```Clojure (ns com.example (:use [amazonica.aws.s3] [amazonica.aws.s3transfer])) (create-bucket "two-peas") ``` -------------------------------- ### Create and List AWS CloudFront Distributions Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create a complex CloudFront distribution configuration, including origins, caching behaviors, and aliases, and how to list existing distributions using Amazonica. ```clj (ns com.example (:use [amazonica.aws.cloudfront])) (create-distribution :distribution-config { :enabled true :default-root-object "index.html" :origins {:quantity 0 :items []} :logging {:enabled false :include-cookies false :bucket "abcd1234.s3.amazonaws.com" :prefix "cflog_"} :caller-reference 12345 :aliases {:items ["m.example.com" "www.example.com"] :quantity 2} :cache-behaviors {:quantity 0 :items []} :comment "example" :default-cache-behavior {:target-origin-id "MyOrigin" :forwarded-values {:query-string false :cookies {:forward "none"}}} :trusted-signers {:enabled false :quantity 0} :viewer-protocol-policy "allow-all" :min-ttl 3600} :price-class "PriceClass_All") (list-distributions :max-items 10) ``` -------------------------------- ### Clojure DynamoDBV2 Delete Table with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This example demonstrates how to delete the 'TestTable' DynamoDB table. This operation permanently removes the table and all its data. ```clj (delete-table cred :table-name "TestTable") ``` -------------------------------- ### Create SimpleDB Domain Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to create a new domain in Amazon SimpleDB. ```Clojure (ns com.example (:require [amazonica.aws.simpledb :as sdb])) (sdb/create-domain :domain-name "domain") ``` -------------------------------- ### Get S3 Object Metadata Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates how to fetch only the metadata of an S3 object without downloading its content, useful for checking properties like content-length. ```Clojure (get-object-metadata :bucket-name bucket1 :key "foo") ``` -------------------------------- ### EC2 Instance and Image Management (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Demonstrates various EC2 operations including launching instances, describing images and instances, creating custom AMIs, and managing EBS snapshots using Amazonica. ```clj (ns com.example (:use [amazonica.aws.ec2])) (-> (run-instances :image-id "ami-54f71039" :instance-type "c3.large" :min-count 1 :max-count 1) (get-in [:reservation :instances 0 :instance-id])) (describe-images :owners ["self"]) (describe-instances :filters [{:name "tag:env" :values ["production"]}]) (create-image :name "my_test_image" :instance-id "i-1b9a9f71" :description "test image - safe to delete" :block-device-mappings [ {:device-name "/dev/sda1" :virtual-name "myvirtual" :ebs { :volume-size 8 :volume-type "standard" :delete-on-termination true}}]) (create-snapshot :volume-id "vol-8a4857fa" :description "my_new_snapshot") ``` -------------------------------- ### Clojure Kinesis Stream Deletion Source: https://github.com/mcohen01/amazonica/blob/master/README.md Provides a simple example of how to delete an existing Kinesis stream using the `delete-stream` function. This is a final cleanup step for Kinesis resources. ```clj (delete-stream "my-stream") ``` -------------------------------- ### Manage AWS CloudSearchV2 Domains and Suggesters Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates creating a CloudSearchV2 domain, indexing documents, building suggesters, and listing all domains using the Amazonica library. ```clj (ns com.example (:use [amazonica.aws.cloudsearchv2])) (create-domain :domain-name "my-index") (index-documents :domain-name "my-index") (build-suggesters :domain-name "my-index") (list-domains) ``` -------------------------------- ### Clojure DynamoDBV2 Get Item with Amazonica Source: https://github.com/mcohen01/amazonica/blob/master/README.md This snippet illustrates how to retrieve a specific item from the 'TestTable' DynamoDB table. It uses the primary key (id and date) to uniquely identify and fetch the desired record. ```clj (get-item cred :table-name "TestTable" :key {:id {:s "foo"} :date {:n 123456}}) ``` -------------------------------- ### Manage S3 Client Options and Credentials (Clojure) Source: https://github.com/mcohen01/amazonica/blob/master/README.md Illustrates how `set-s3client-options` uses the default credential provider chain, while a subsequent call like `create-bucket` with explicit credentials will instantiate a separate AmazonS3Client, highlighting client caching behavior. ```clj (set-s3client-options :path-style-access true) (create-bucket credentials "foo") ``` -------------------------------- ### List SimpleDB Domains Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to list all domains in Amazon SimpleDB. ```Clojure (sdb/list-domains) ``` -------------------------------- ### Create and Index AWS CloudSearch Domains Source: https://github.com/mcohen01/amazonica/blob/master/README.md Shows how to create a new CloudSearch domain and initiate the indexing of documents within that domain using the Amazonica library. ```clj (ns com.example (:use [amazonica.aws.cloudsearch])) (create-domain :domain-name "my-index") (index-documents :domain-name "my-index") ```