Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan CreateGateway
dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanCreateGateway
.
- CLI
-
- AWS CLI
-
Untuk membuat gateway
create-gateway
Contoh berikut membuat gateway yang berjalan di AWS IoT Greengrass.aws iotsitewise create-gateway \ --gateway-name
ExampleCorpGateway
\ --gateway-platformgreengrass={groupArn=arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/a1b2c3d4-5678-90ab-cdef-1b1b1EXAMPLE}
Output:
{ "gatewayId": "a1b2c3d4-5678-90ab-cdef-1a1a1EXAMPLE", "gatewayArn": "arn:aws:iotsitewise:us-west-2:123456789012:gateway/a1b2c3d4-5678-90ab-cdef-1a1a1EXAMPLE" }
Untuk informasi selengkapnya, lihat Mengonfigurasi gateway di Panduan AWS Pengguna SiteWise IoT.
-
Untuk API detailnya, lihat CreateGateway
di Referensi AWS CLI Perintah.
-
- Java
-
- SDKuntuk Java 2.x
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. /** * Creates a new IoT Sitewise gateway. * * @param gatewayName The name of the gateway to create. * @param myThing The name of the core device thing to associate with the gateway. * @return a {@link CompletableFuture} that represents a {@link String} result of the gateways ID. The calling code * can attach callbacks, then handle the result or exception by calling {@link CompletableFuture#join()} or * {@link CompletableFuture#get()}. * <p> * If any completion stage in this method throws an exception, the method logs the exception cause and keeps * it available to the calling code as a {@link CompletionException}. By calling * {@link CompletionException#getCause()}, the calling code can access the original exception. */ public CompletableFuture<String> createGatewayAsync(String gatewayName, String myThing) { GreengrassV2 gg = GreengrassV2.builder() .coreDeviceThingName(myThing) .build(); GatewayPlatform platform = GatewayPlatform.builder() .greengrassV2(gg) .build(); Map<String, String> tag = new HashMap<>(); tag.put("Environment", "Production"); CreateGatewayRequest createGatewayRequest = CreateGatewayRequest.builder() .gatewayName(gatewayName) .gatewayPlatform(platform) .tags(tag) .build(); return getAsyncClient().createGateway(createGatewayRequest) .handle((response, exception) -> { if (exception != null) { logger.error("Error creating the gateway."); throw (CompletionException) exception; } logger.info("The ARN of the gateway is {}" , response.gatewayArn()); return response.gatewayId(); }); }
-
Untuk API detailnya, lihat CreateGatewaydi AWS SDK for Java 2.x APIReferensi.
-