MCPcopy Create free account
hub / github.com/api3dao/airnode / main

Function main

packages/airnode-examples/src/scripts/create-aws-secrets.ts:6–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { cliPrint, formatSecrets, promptQuestions, readAwsSecrets, readIntegrationInfo, runAndHandleErrors } from '../';
5
6const main = async () => {
7 const integrationInfo = readIntegrationInfo();
8 if (integrationInfo.airnodeType !== 'aws') {
9 cliPrint.error('You only need to run this script if you want to deploy Airnode on AWS');
10 return;
11 }
12
13 // We try to populate the options with initial values from the existing `aws.env` (if it exists)
14 const awsSecrets = existsSync(join(__dirname, `../../integrations/${integrationInfo.integration}/aws.env`))
15 ? readAwsSecrets()
16 : null;
17 const questions: PromptObject[] = [
18 {
19 type: 'text',
20 name: 'accessKeyId',
21 message: [
22 'In order to deploy to AWS, your access and secret keys are required.',
23 'Secrets and keys you enter here will remain on your machine and will not be uploaded anywhere.',
24 '',
25 'See video how to create these: https://www.youtube.com/watch?v=KngM5bfpttA',
26 '',
27 'Enter AWS access key ID',
28 ].join('\n'),
29 initial: awsSecrets?.AWS_ACCESS_KEY_ID,
30 },
31 {
32 type: 'text',
33 name: 'secretAccessKey',
34 message: 'Enter AWS secret access key',
35 initial: awsSecrets?.AWS_SECRET_ACCESS_KEY,
36 },
37 {
38 type: 'text',
39 name: 'sessionToken',
40 message: '(Optional) Enter AWS session token',
41 initial: awsSecrets?.AWS_SESSION_TOKEN,
42 },
43 ];
44
45 const response = await promptQuestions(questions);
46 const airnodeSecrets = [
47 `# This file was generated by: ${relative(__dirname, __filename)}`,
48 '# ',
49 '# For further information see:',
50 '# https://airnode-docs.api3.org/reference/airnode/latest/understand/configuring.html#aws-setup-aws-deployment-only',
51 `AWS_ACCESS_KEY_ID=${response.accessKeyId}`,
52 `AWS_SECRET_ACCESS_KEY=${response.secretAccessKey}`,
53 `AWS_SESSION_TOKEN=${response.sessionToken}`,
54 ];
55
56 writeFileSync(
57 join(__dirname, `../../integrations/${integrationInfo.integration}/aws.env`),
58 formatSecrets(airnodeSecrets)
59 );
60 cliPrint.info(`An 'aws.env' file with the required credentials has been created.`);
61};
62
63runAndHandleErrors(main);

Callers

nothing calls this directly

Calls 5

readIntegrationInfoFunction · 0.85
readAwsSecretsFunction · 0.85
promptQuestionsFunction · 0.85
formatSecretsFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected