Skip to content

Commit d4c7f91

Browse files
authored
Change AWS credentials to Lightning ones (#13703)
1 parent d058190 commit d4c7f91

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/lightning_app/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1212

1313
### Changed
1414

15+
- Added `LIGHTNING_` prefix to Platform AWS credentials ([#13703](https://github.com/Lightning-AI/lightning/pull/13703))
16+
1517
### Deprecated
1618

1719
### Fixed

src/lightning_app/storage/path.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,12 @@ def filesystem() -> AbstractFileSystem:
408408
endpoint_url = os.getenv("LIGHTNING_BUCKET_ENDPOINT_URL", "")
409409
bucket_name = os.getenv("LIGHTNING_BUCKET_NAME", "")
410410
if endpoint_url != "" and bucket_name != "":
411-
key = os.getenv("AWS_ACCESS_KEY_ID", "")
412-
secret = os.getenv("AWS_SECRET_ACCESS_KEY", "")
411+
key = os.getenv("LIGHTNING_AWS_ACCESS_KEY_ID", "")
412+
secret = os.getenv("LIGHTNING_AWS_SECRET_ACCESS_KEY", "")
413+
# TODO: Remove when updated on the platform side.
414+
if key == "" or secret == "":
415+
key = os.getenv("AWS_ACCESS_KEY_ID", "")
416+
secret = os.getenv("AWS_SECRET_ACCESS_KEY", "")
413417
if key == "" or secret == "":
414418
raise RuntimeError("missing S3 bucket credentials")
415419

tests/tests_app/storage/test_path.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
from re import escape
66
from time import sleep
77
from unittest import mock
8-
from unittest.mock import Mock
8+
from unittest.mock import MagicMock, Mock
99

1010
import pytest
1111

1212
from lightning_app import LightningApp, LightningFlow, LightningWork
1313
from lightning_app.runners import MultiProcessRuntime
14-
from lightning_app.storage.path import artifacts_path, is_lit_path, Path, shared_storage_path, storage_root_dir
14+
from lightning_app.storage.path import (
15+
_is_s3fs_available,
16+
artifacts_path,
17+
filesystem,
18+
is_lit_path,
19+
Path,
20+
shared_storage_path,
21+
storage_root_dir,
22+
)
1523
from lightning_app.storage.requests import ExistsResponse, GetResponse
1624
from lightning_app.testing.helpers import EmptyWork, MockQueue, RunIf
1725
from lightning_app.utilities.app_helpers import LightningJSONEncoder
@@ -678,3 +686,21 @@ def test_artifacts_path():
678686
work = Mock()
679687
work.name = "root.flow.work"
680688
assert artifacts_path(work) == shared_storage_path() / "artifacts" / "root.flow.work"
689+
690+
691+
@pytest.mark.skipif(not _is_s3fs_available(), reason="This test requires s3fs.")
692+
@mock.patch.dict(os.environ, {"LIGHTNING_BUCKET_ENDPOINT_URL": "a"})
693+
@mock.patch.dict(os.environ, {"LIGHTNING_BUCKET_NAME": "b"})
694+
@mock.patch.dict(os.environ, {"LIGHTNING_AWS_ACCESS_KEY_ID": "c"})
695+
@mock.patch.dict(os.environ, {"LIGHTNING_AWS_SECRET_ACCESS_KEY": "d"})
696+
@mock.patch.dict(os.environ, {"LIGHTNING_CLOUD_APP_ID": "e"})
697+
def test_filesystem(monkeypatch):
698+
from lightning_app.storage import path
699+
700+
mock = MagicMock()
701+
monkeypatch.setattr(path, "S3FileSystem", mock)
702+
fs = filesystem()
703+
assert fs._mock_new_parent._mock_mock_calls[0].kwargs["key"] == "c"
704+
assert fs._mock_new_parent._mock_mock_calls[0].kwargs["secret"] == "d"
705+
assert not fs._mock_new_parent._mock_mock_calls[0].kwargs["use_ssl"]
706+
assert fs._mock_new_parent._mock_mock_calls[0].kwargs["client_kwargs"] == {"endpoint_url": "a"}

0 commit comments

Comments
 (0)