-
Notifications
You must be signed in to change notification settings - Fork 16
nisar and other updates #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4f78a50
d5fd743
dc6f55e
9720837
ddc1553
1ef24f2
7a297f9
8a89fd1
b8da8ac
9757cc8
e4d50b5
ca1c35b
2767c0d
0392660
a91235c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,23 +8,114 @@ | |
| "\n", | ||
| "When logged into the ADE, temporary s3 credentials can be issued using the maap-py function `maap.aws.workspace_bucket_credentials()`\n", | ||
| "\n", | ||
| "This command issues a set of AWS credentials that grant full read/write access to your own user folder within the `maap-ops-workspace` bucket. Access is given to the directory corresponding to your `my-private-bucket` folder within the ADE. \n", | ||
| "This command issues a set of AWS credentials that grant full read/write access to your own user folder within the workspace bucket, as well as any additional S3 buckets your organization has been granted access to.\n", | ||
| "\n", | ||
| "```python\n", | ||
| "The response contains:\n", | ||
| "- `credentials` — temporary AWS credentials (`aws_access_key_id`, `aws_secret_access_key`, `aws_session_token`, `expires_at`)\n", | ||
| "- `authorized_s3_paths` — an array of accessible paths, each with `bucket`, `prefix`, `uri`, `type` (`workspace` or `org`), and `access` (`read_write` or `read_only`)\n", | ||
| "\n", | ||
| "### 1. Retrieve temporary credentials\n", | ||
| "\n", | ||
| "```python\n", | ||
| "import json\n", | ||
| "from maap.maap import MAAP\n", | ||
| "maap = MAAP()\n", | ||
| "\n", | ||
| "print(json.dumps(maap.aws.workspace_bucket_credentials(), indent=2))\n", | ||
| "resp = maap.aws.workspace_bucket_credentials()\n", | ||
| "print(json.dumps(resp, indent=2))\n", | ||
| ">>> {\n", | ||
| " \"aws_access_key_id\": \"...\",\n", | ||
| " \"aws_bucket_name\": \"maap-ops-workspace\",\n", | ||
| " \"aws_bucket_prefix\": \"maap_user\",\n", | ||
| " \"aws_secret_access_key\": \"...\",\n", | ||
| " \"aws_session_expiration\": \"...\",\n", | ||
| " \"aws_session_token\": \"...\"\n", | ||
| " \"credentials\": {\n", | ||
| " \"aws_access_key_id\": \"...\",\n", | ||
| " \"aws_secret_access_key\": \"...\",\n", | ||
| " \"aws_session_token\": \"...\",\n", | ||
| " \"expires_at\": \"2025-03-03T18:00:00Z\"\n", | ||
| " },\n", | ||
| " \"authorized_s3_paths\": [\n", | ||
| " {\n", | ||
| " \"bucket\": \"maap-ops-workspace\",\n", | ||
| " \"prefix\": \"maap_user\",\n", | ||
| " \"uri\": \"s3://maap-ops-workspace/maap_user\",\n", | ||
| " \"type\": \"workspace\",\n", | ||
| " \"access\": \"read_write\"\n", | ||
| " },\n", | ||
| " {\n", | ||
| " \"bucket\": \"shared-project-bucket\",\n", | ||
| " \"prefix\": \"team-data\",\n", | ||
| " \"uri\": \"s3://shared-project-bucket/team-data\",\n", | ||
| " \"type\": \"org\",\n", | ||
| " \"access\": \"read_write\"\n", | ||
| " },\n", | ||
| " {\n", | ||
| " \"bucket\": \"public-reference-data\",\n", | ||
| " \"prefix\": \"smap/v9\",\n", | ||
| " \"uri\": \"s3://public-reference-data/smap/v9\",\n", | ||
| " \"type\": \"org\",\n", | ||
| " \"access\": \"read_only\"\n", | ||
| " }\n", | ||
| " ]\n", | ||
| "}\n", | ||
| "```\n", | ||
| "\n", | ||
| "### 2. Create a boto3 session from the credentials\n", | ||
| "\n", | ||
| "```python\n", | ||
| "import boto3\n", | ||
| "\n", | ||
| "creds = resp[\"credentials\"]\n", | ||
| "session = boto3.Session(\n", | ||
| " aws_access_key_id=creds[\"aws_access_key_id\"],\n", | ||
| " aws_secret_access_key=creds[\"aws_secret_access_key\"],\n", | ||
| " aws_session_token=creds[\"aws_session_token\"],\n", | ||
| ")\n", | ||
| "s3 = session.client(\"s3\")\n", | ||
| "```\n", | ||
| "\n", | ||
| "### 3. Working with your workspace bucket\n", | ||
| "\n", | ||
| "The workspace path is always the first entry in `authorized_s3_paths`. Use the `bucket` and `prefix` fields directly:\n", | ||
| "\n", | ||
| "```python\n", | ||
| "workspace = resp[\"authorized_s3_paths\"][0]\n", | ||
| "bucket = workspace[\"bucket\"]\n", | ||
| "prefix = resp.get(\"prefix\") or \"\"\n", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't working for me because resp doesn't have Also, this code doesn't work for me for 2i2c but does in the ADE |
||
| "shared_prefix = prefix + (\"/\" if prefix else \"\")\n", | ||
| "\n", | ||
| "# List objects\n", | ||
| "response = s3.list_objects_v2(Bucket=bucket, Prefix=shared_prefix, MaxKeys=10)\n", | ||
| "for obj in response.get(\"Contents\", []):\n", | ||
| " print(obj[\"Key\"])\n", | ||
| "\n", | ||
| "# Download a file\n", | ||
| "s3.download_file(Bucket=bucket, Key=f\"{shared_prefix}my_file.csv\", Filename=\"my_file.csv\")\n", | ||
| "\n", | ||
| "# Upload a file\n", | ||
| "s3.upload_file(Filename=\"local_results.csv\", Bucket=bucket, Key=f\"{shared_prefix}local_results.csv\")\n", | ||
| "```\n", | ||
| "\n", | ||
| "### 4. Working with organization shared buckets\n", | ||
| "\n", | ||
| "Additional org-granted buckets appear as extra entries. Each entry tells you whether it is `read_write` or `read_only`:\n", | ||
| "\n", | ||
| "```python\n", | ||
| "for path in resp[\"authorized_s3_paths\"]:\n", | ||
| " print(f\"{path['uri']} ({path['access']})\")\n", | ||
| "\n", | ||
| "# Access a specific org bucket\n", | ||
| "shared = resp[\"authorized_s3_paths\"][1]\n", | ||
| "shared_bucket = shared[\"bucket\"]\n", | ||
| "shared_prefix = shared[\"prefix\"]\n", | ||
| "\n", | ||
| "# List files\n", | ||
| "response = s3.list_objects_v2(Bucket=shared_bucket, Prefix=shared_prefix, MaxKeys=10)\n", | ||
| "for obj in response.get(\"Contents\", []):\n", | ||
| " print(obj[\"Key\"])\n", | ||
| "\n", | ||
| "# Download a file\n", | ||
| "s3.download_file(Bucket=shared_bucket, Key=f\"{shared_prefix}shared_dataset.tif\", Filename=\"shared_dataset.tif\")\n", | ||
| "\n", | ||
| "# Upload a file (only works if access is \"read_write\")\n", | ||
| "if shared[\"access\"] == \"read_write\":\n", | ||
| " s3.upload_file(Filename=\"my_output.tif\", Bucket=shared_bucket, Key=f\"{shared_prefix}my_output.tif\")\n", | ||
| "```" | ||
| ] | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.