How to import/share a lib/class between component in ggv2

0

Hi there,

I am just wondering is there a way that I can reuse my code between the component, kind of like lambda layer

eg:

foo
-- src
---- send_mqtt

foo2
-- src
---- send_mqtt

So how can i use request the send_mqtt ?

Thanks for your help

質問済み 2年前234ビュー
1回答
0
承認された回答

Hi,

you could create a component which deploys send_mqtt. Then you create your foo and foo2 components with a dependency to send_mqtt.

A particular recipes example could look like:

  • send_mqtt
{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": "my.send_mqtt",
  "ComponentVersion": "1.0.0",
  "ComponentDescription": "Send messages via MQTT",
  "ComponentPublisher": "Myself",
  "Manifests": [
    {
      "Platform": {
        "os": "linux"
      },
      "Lifecycle": {
        "Install": "pip3 install --user -r {artifacts:decompressedPath}/send_mqtt/requirements.txt"
      },
      "Artifacts": [
        {
          "URI": "s3://MY_BUCKET/my.send_mqtt/1.0.0/send_mqtt.zip",
          "Unarchive": "ZIP"
        }
      ]
    }
  ]
}
  • foo recipe
{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": "my.foo",
  "ComponentVersion": "1.0.0",
  "ComponentDescription": "Foo",
  "ComponentPublisher": "Myself",
  "ComponentDependencies": {
    "my.send_mqtt": {
      "VersionRequirement": "^1.0.0"
    }
  },
  "Manifests": [
    {
      "Platform": {
        "os": "linux"
      },
      "Lifecycle": {
        "Run": "export PYTHONPATH=$PYTHONPATH:{my.send_mqtt:artifacts:decompressedPath}/send_mqtt; python3 {artifacts:path}/foo.py"
      },
      "Artifacts": [
        {
          "URI": "s3://MY_BUCKET/my.foo/1.0.0/foo.py"
        }
      ]
    }
  ]
}

In foo.py you can then import send_mqtt.

KR,

Philipp

AWS
エキスパート
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ