Skip to content

Commit d5a3741

Browse files
authored
Merge pull request #22 from NHSDigital/AMB-1684-Create-AWS-resources
AMB-1684-Create-AWS-resources
2 parents 1ec69d3 + a075e58 commit d5a3741

35 files changed

+1660
-519
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ __pycache__/
1616
.venv/
1717
.env
1818
smoketest-report.xml
19+
lambda_typescript/**/*.js
20+
terraform/zips
1921
.dir-locals.el
2022
*.pyc
2123
.python-version

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SHELL=/bin/bash -euo pipefail
22

33
#Installs dependencies using poetry.
44
install-python:
5+
poetry lock --no-update
56
poetry install
67

78
#Installs dependencies using npm.
@@ -17,6 +18,7 @@ install: install-node install-python .git/hooks/pre-commit
1718

1819
#Run the npm linting script (specified in package.json). Used to check the syntax and formatting of files.
1920
lint:
21+
npm run lint
2022
find . -name '*.py' -not -path '**/.venv/*' | xargs poetry run flake8
2123

2224
#Removes build/ + dist/ directories
@@ -36,7 +38,7 @@ build-proxy:
3638
scripts/build_proxy.sh
3739

3840
#Files to loop over in release
39-
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests specification sandbox terraform"
41+
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests specification sandbox terraform lambda_typescript scripts"
4042

4143
#Create /dist/ sub-directory and copy files into directory
4244
release: clean publish build-proxy

azure/azure-pr-pipeline.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ extends:
3434
service_base_path: ${{ variables.service_base_path }}
3535
apigee_deployments:
3636
- environment: internal-dev
37+
jinja_templates:
38+
DOMAIN_ENDPOINT: https://pr-${{ variables.pr_number }}.imms.dev.api.platform.nhs.uk
3739
post_deploy:
3840
- template: ./templates/post-deploy.yml
3941
- environment: internal-dev-sandbox
4042
proxy_path: sandbox
43+
jinja_templates:
44+
DOMAIN_ENDPOINT: just-dummy-value-for-successful-build
4145
post_deploy:
4246
- template: ./templates/post-deploy.yml
47+

azure/azure-release-pipeline.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ extends:
3232
service_base_path: ${{ variables.service_base_path }}
3333
apigee_deployments:
3434
- environment: internal-dev
35+
jinja_templates:
36+
DOMAIN_ENDPOINT: https://internal-dev.imms.dev.api.platform.nhs.uk
3537
post_deploy:
3638
- template: ./templates/post-deploy.yml
3739
- environment: internal-dev-sandbox
3840
proxy_path: sandbox
41+
jinja_templates:
42+
DOMAIN_ENDPOINT: just-dummy-value-for-successful-build
3943
post_deploy:
4044
- template: ./templates/post-deploy.yml
4145
- environment: sandbox
4246
proxy_path: sandbox
47+
jinja_templates:
48+
DOMAIN_ENDPOINT: just-dummy-value-for-successful-build
4349
depends_on:
4450
- internal_dev_sandbox
4551
# # Enable int environment when ready by uncommenting:

azure/project.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ variables:
66
value: ifa
77
- name: service_base_path
88
value: immunisation-fhir-api
9+
- name: pr_number
10+
value: ${{ split(variables['Build.SourceBranch'], '/')[2] }}
11+

azure/templates/post-deploy.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ steps:
1010
parameters:
1111
role: "auto-ops"
1212
profile: "apm_ptl"
13+
14+
- template: "azure/components/get-aws-secrets-and-ssm-params.yml@common"
15+
parameters:
16+
secret_file_ids:
17+
- ptl/app-credentials/jwt_testing/non-prod/JWT_TESTING_PRIVATE_KEY
18+
secret_ids:
19+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_ID
20+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_SECRET
21+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_ID_INT
22+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_SECRET_INT
1323

1424
- bash: |
1525
make install-python
@@ -47,7 +57,7 @@ steps:
4757
cd terraform
4858
make init
4959
make apply aws_account_no=${aws_account_no} environment=$workspace
50-
cd ..
60+
5161
fi
5262
displayName: Deploy sandbox
5363
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)"

lambda_typescript/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# immunisation-fhir-api
2+
This is lambdas for the *immunisation-fhir-api* API.
3+
4+
## Set up your TypeScript Lambda function:
5+
Make sure you have your TypeScript Lambda function code structured properly in a directory. For example, you might have a directory structure like this:
6+
lambda/
7+
├── src/
8+
│ └── index.ts
9+
├── package.json
10+
└── tsconfig.json
11+
12+
## Install npm dependencies (if any):
13+
14+
If your TypeScript Lambda function has npm dependencies, make sure they are installed in the project directory. You can do this by running:
15+
`npm install`
16+
17+
### Build your TypeScript code:
18+
Before creating a ZIP file, you need to build your TypeScript code into JavaScript. Navigate to the directory where your tsconfig.json file is located and run:
19+
`tsc`
20+
This command will compile your TypeScript code into JavaScript and place the output files in the specified directory.
21+
22+
In the package.json, added this build command in the scripts:
23+
` "build": "tsc" `
24+
25+
26+
### Create a ZIP file:
27+
To create a ZIP file containing your Lambda function code, navigate to the directory where your TypeScript code and built JavaScript files are located. Then, create a ZIP archive that includes your Lambda function code and its dependencies (if any) using the zip command.
28+
29+
### Specify the ZIP file in your Terraform configuration:
30+
In your Terraform configuration for the Lambda function, you can specify the location of the ZIP file using the filename argument in the aws_lambda_function resource block.

lambda_typescript/deploy.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
# Run the npm commands to transpile the TypeScript to JavaScript
4+
npm i && \
5+
npm run build && \
6+
npm prune --production &&\
7+
# Create a dist folder and copy only the js files to distribution.
8+
# AWS Lambda does not have a use for a package.json or typescript files on runtime.
9+
mkdir dist &&\
10+
cp -r ./src/*.js dist/ &&\
11+
cp -r ./node_modules dist/ &&\
12+
cd dist &&\
13+
find . -name "*.zip" -type f -delete && \
14+
#Create zips directory under terraform, delete existing one
15+
rm -rf ../../terraform/zips
16+
mkdir ../../terraform/zips
17+
# Zip everything in the dist folder and move to terraform directory
18+
zip -r ../../terraform/zips/lambda_function.zip . && \
19+
#Delete Distibution folder
20+
cd .. && rm -rf dist

lambda_typescript/package-lock.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lambda_typescript/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "lambda",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "tsc"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"@types/node": "^20.5.9",
14+
"typescript": "^5.2.2"
15+
},
16+
"dependencies": {
17+
"aws-sdk": "^2.1450.0"
18+
}
19+
}

0 commit comments

Comments
 (0)